monthly_planner 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/monthly_planner.rb +45 -8
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4c824906739e5fe60be57015b323f02cf92987b
|
4
|
+
data.tar.gz: cd1fa7fc0e9339f05d1ca3dfddfd36e74db3cd34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c1e5ac19935ed7521f7549e6ea4be0c137caef931e893bc098d50f3f6328aea964dc792685c65903b79697444a1068160ec5d462b59eb1c2529a38ac2a22e0
|
7
|
+
data.tar.gz: 6ab3909c86179ae7a8c584038e2efea871594f9c19515182c176892d5ba3f140e02251969cac48fc1e699f930d3ab7644ac5fcb71b2fb1c080112836bb187160
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/monthly_planner.rb
CHANGED
@@ -7,6 +7,10 @@ require 'dynarex'
|
|
7
7
|
require 'fileutils'
|
8
8
|
|
9
9
|
|
10
|
+
# The MonthlyPlanner gem can:
|
11
|
+
#
|
12
|
+
# * create a new monthly-planner.txt file
|
13
|
+
# * read an existing monthly-planner.txt file
|
10
14
|
|
11
15
|
class MonthlyPlanner
|
12
16
|
|
@@ -17,7 +21,13 @@ class MonthlyPlanner
|
|
17
21
|
@filename, @path = filename, path
|
18
22
|
|
19
23
|
fpath = File.join(path, filename)
|
20
|
-
|
24
|
+
|
25
|
+
if File.exists?(fpath) then
|
26
|
+
|
27
|
+
@dx = import_to_dx(File.read(fpath))
|
28
|
+
else
|
29
|
+
@dx = new_dx
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
def dx()
|
@@ -40,23 +50,50 @@ class MonthlyPlanner
|
|
40
50
|
|
41
51
|
def dx_to_s(dx)
|
42
52
|
|
43
|
-
|
44
|
-
|
53
|
+
rows = dx.all.map do |x|
|
54
|
+
%i(date time desc).map{|y| !x[y].empty? ? x[y] + ' ' : '' }.join
|
55
|
+
end
|
56
|
+
|
45
57
|
title = File.basename(@filename)
|
46
|
-
title + "\n" + "=" * title.length + "\n\n%s\n\n" % [rows.join("\n
|
58
|
+
title + "\n" + "=" * title.length + "\n\n%s\n\n" % [rows.join("\n")]
|
47
59
|
|
48
60
|
end
|
49
61
|
|
62
|
+
def import_to_dx(s)
|
63
|
+
|
64
|
+
regexp = %r{
|
65
|
+
|
66
|
+
(?<day>\d+(?:-|th|[rn]d|st)){0}
|
67
|
+
(?<month>#{Date::ABBR_MONTHNAMES[1..-1].join('|')}){0}
|
68
|
+
(?<time>\d+[ap]m){0}
|
69
|
+
|
70
|
+
^(?<date>\g<day>\s*\g<month>)\s*\g<time>?\s*(?<event>.*)
|
71
|
+
}x
|
72
|
+
|
73
|
+
dx = new_dx()
|
74
|
+
a = LineTree.new(s).to_a
|
75
|
+
|
76
|
+
# Remove the heading
|
77
|
+
a.shift 2
|
78
|
+
|
79
|
+
a.each do |line|
|
80
|
+
r = line[0].match(regexp)
|
81
|
+
dx.create({date: r['date'], time: r['time'], desc: r['event']})
|
82
|
+
end
|
83
|
+
|
84
|
+
return dx
|
85
|
+
end
|
86
|
+
|
50
87
|
def new_dx()
|
51
88
|
|
52
|
-
dx = Dynarex.new 'month[title]/day(date, desc, uid)'
|
89
|
+
dx = Dynarex.new 'month[title]/day(date, time, desc, uid)',
|
90
|
+
default_key: :uid
|
53
91
|
|
54
92
|
d = DateTime.now.to_date
|
55
|
-
title = %
|
56
|
-
.map {|x| d.method(x).call.strftime("%b")}.join(' - ')
|
93
|
+
title = [d, d.next_month].map {|x| x.strftime("%b")}.join(' - ')
|
57
94
|
dx.title = "Monthly Planner (%s)" % title
|
58
95
|
|
59
96
|
return dx
|
60
97
|
end
|
61
98
|
|
62
|
-
end
|
99
|
+
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|