5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/diary-ruby/parser.rb', line 5
def self.parse(infile)
= []
body = []
= true
split_match = /^---+$/
Diary.debug("PARSE #{ infile.size } BYTES")
infile.lines.each do |line|
if
if split_match =~ line
= false
next
end
<< line
else
body << line
end
end
metadata = {}
key_match = /^([A-Za-z_-]+):? (.+)$/
.each do |h_line|
if key_match =~ h_line
key = $1.strip.downcase
val = $2.strip
if /tags/i =~ key
val = val.split(',').map {|v| v.strip}
end
metadata[key] = val
end
end
key = Entry.keygen(metadata['day'], metadata['time'])
Diary.debug "KEY #{ key }"
Diary.debug "METADATA #{ metadata.inspect }"
Diary.debug "BODY #{ body.join(" ") }"
return Entry.new(
day: metadata['day'],
time: metadata['time'],
tags: metadata['tags'],
body: body.join("\n").strip,
title: metadata['title'],
key: key,
)
end
|