diff options
author | 2014-08-27 10:48:59 -0700 | |
---|---|---|
committer | 2014-08-27 10:48:59 -0700 | |
commit | 61d03f1ca87f0ca25b98cd5919d6587e26a11b53 (patch) | |
tree | 5466c2d0463e962cfdfe9e074c4add250746624b /lib | |
parent | Merge branch 'old-master' (diff) | |
download | infra-status-61d03f1ca87f0ca25b98cd5919d6587e26a11b53.tar.gz infra-status-61d03f1ca87f0ca25b98cd5919d6587e26a11b53.tar.bz2 infra-status-61d03f1ca87f0ca25b98cd5919d6587e26a11b53.zip |
Improve handling of description detection.
Signed-off-by: Robin H. Johnson <robbat2@orbis-terrarum.net>
Diffstat (limited to 'lib')
-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 |