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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/wooden.rb', line 13
def entry(natural_language, options = {})
parsed = Nickel.parse(natural_language)
occurrence = parsed.occurrences.first
return false if occurrence.nil?
remind_parts = ["REM"]
date_txt, time_txt = "", ""
if occurrence.start_date
date = occurrence.start_date
remind_parts << date.to_date.strftime("%d %b %Y")
date_txt = %[ #{date.to_date.strftime("%d-%b-%Y")}]
end
if occurrence.start_time
time = occurrence.start_time
remind_parts << "AT #{time.to_time.strftime('%H:%M')}"
time_txt = %[ #{time.to_time.strftime("%H:%M")}]
end
if occurrence.type == :daily
remind_parts.insert(1, "*1")
elsif occurrence.type == :weekly
day_name = occurrence.start_date.to_date.strftime("%A") if occurrence.start_date
remind_parts[1] = day_name if day_name
elsif occurrence.type == :monthly
remind_parts.insert(1, "*1")
elsif occurrence.type == :yearly
if occurrence.start_date
remind_parts[1] = occurrence.start_date.to_date.strftime("%d %b")
end
end
if options[:duration]
remind_parts << "DURATION #{options[:duration]}"
end
if options[:lead]
remind_parts.insert(1, "+#{options[:lead]}")
end
if options[:delta]
remind_parts << "*#{options[:delta]}"
end
if options[:priority]
remind_parts << "PRIORITY #{options[:priority]}"
end
if options[:tag]
remind_parts << "TAG #{options[:tag]}"
end
message = options[:message] || parsed.message || "Reminder"
remind_parts << "MSG"
dt = "#{date_txt}#{time_txt}"
if dt.length > 0
remind_parts << dt.strip
end
remind_parts << "%a"
remind_parts << "%b"
msg_tokens = []
msg_tokens << "%\"%" if options[:quiet]
final_message = msg_tokens.join(" ") + " " + message
remind_parts << final_message.strip
if options[:until]
until_str = "UNTIL #{options[:until].strftime('%d %b %Y')}"
msg_index = remind_parts.index("MSG")
remind_parts.insert(msg_index, until_str)
end
if options[:omit]
omit_days = Array(options[:omit]).join(" ")
msg_index = remind_parts.index("MSG")
remind_parts.insert(msg_index, "OMIT #{omit_days}")
end
if options[:skip]
msg_index = remind_parts.index("MSG")
remind_parts.insert(msg_index, "SKIP")
end
File.open("rem/#{@id}.rem", 'a') { |f| f.puts(remind_parts.join(" ")) }
ff = File.read("rem/#{@id}.rem").split("\n").uniq.filter { |e| e.length > 0 }
File.open("rem/#{@id}.rem", 'w') { |f| f.write("") }
ff.each { |e| File.open("rem/#{@id}.rem", 'a') { |f| f.puts(e) } }
return nil
end
|