diff options
-rw-r--r-- | lib/notice_store.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/notice_store.rb b/lib/notice_store.rb index e3bb2bd..a825ee9 100644 --- a/lib/notice_store.rb +++ b/lib/notice_store.rb @@ -89,8 +89,20 @@ class Notice content = File.read(filename) metadata = YAML.load(content) || {} metadata['updated_at'] = File.mtime(filename) + description = 'missing description' + description_splitpos = undef + + lines = content.split("\n").map { |l| l.strip } + if lines[0] == '---' and lines.grep('---').length() >= 2 + description_splitpos = 2 + elsif lines.grep('---').length() >= 1 + description_splitpos = 1 + else + description_splitpos = 0 + end - new(File.basename(filename, '.txt'), metadata, content.split('---')[2].strip) + description = content.split('---')[description_splitpos].strip + new(File.basename(filename, '.txt'), metadata, description) end def [](what) @@ -124,4 +136,4 @@ class Notice @metadata['id'] = id @content = content end -end
\ No newline at end of file +end |