weekly_planner 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcc9be272018ca4c1ed5f7acf006c877c1dbf9c4
4
- data.tar.gz: e5805310a96ba8611a520bed7ca8cf20014b13ac
3
+ metadata.gz: c449a1287de09f9dc3a8eeac9bea5320af286845
4
+ data.tar.gz: 570e60554cb6693fc0e7fd85540f2bf6a2e8c671
5
5
  SHA512:
6
- metadata.gz: abafb6f96d7d4f0f927cb82a9f1324e925fbc61b9e41da49083e3b578b31acee67a5c7a464544d4378f51bf06e703b5455b88c3f66ffbca81393b04fa6abaf02
7
- data.tar.gz: b1590914a4e1d687bddfeb94d8e1f5abfc7ef0162dab1745de1d9b91765dcfb37eefa316b5ff1372b0282a0a22b23d9a0a94fc44d4ffa56234572310d7529fa0
6
+ metadata.gz: 7257b020f03bac607a410c6b990bca34d875b239feeaf92a24e67019840c915f260cb6c99c2435be1943577194ef796eb8123fbb2842d7f92d8b1735c24b0775
7
+ data.tar.gz: 537d4104dbe2edb2b7878cf63cb08fede7a7915ced7636a942be68eb987c9217524fb8be4bc62c992629ee1c57034afc5bfa71269d7ce8b192d828f184ec6f5a
checksums.yaml.gz.sig CHANGED
Binary file
@@ -7,6 +7,7 @@ require 'dynarex'
7
7
  require 'fileutils'
8
8
 
9
9
 
10
+
10
11
  class WeeklyPlanner
11
12
 
12
13
  attr_reader :to_s
@@ -16,8 +17,37 @@ class WeeklyPlanner
16
17
  @filename, @path = filename, path
17
18
 
18
19
  fpath = File.join(path, filename)
19
- @s = File.exists?(fpath) ? File.read(fpath) : create()
20
- @dx = create_dx(@s)
20
+
21
+ if File.exists?(fpath) then
22
+
23
+ s = File.read(fpath)
24
+ @dx = import_to_dx(s)
25
+ archive()
26
+
27
+ # purge any past dates
28
+ while Date.parse(@dx.all.first.id, "%Y%m%d") != DateTime.now.to_date \
29
+ and @dx.all.length > 0 do
30
+ @dx.all.first.delete
31
+
32
+ end
33
+
34
+ # new days to add?
35
+ len = 7 - @dx.all.length
36
+
37
+ if len > 0 then
38
+
39
+ date = Date.strptime(@dx.all.last.id, "%Y%m%d") + 1
40
+
41
+ len.times.with_index do |row, i|
42
+ @dx.create({x: (date + i).strftime("# %d-%b-%Y\n\n")}, \
43
+ id: (date + i).strftime("%Y%m%d"))
44
+ end
45
+
46
+ end
47
+
48
+ else
49
+ @dx = new_dx
50
+ end
21
51
 
22
52
  end
23
53
 
@@ -27,9 +57,21 @@ class WeeklyPlanner
27
57
 
28
58
  def save(filename=@filename)
29
59
 
30
- s = File.basename(filename) + "\n" + @s.lines[1..-1].join
60
+ s = File.basename(filename) + "\n" + dx_to_s(@dx).lines[1..-1].join
31
61
  File.write File.join(@path, filename), s
32
62
 
63
+ archive()
64
+
65
+ end
66
+
67
+ def to_s()
68
+ dx_to_s @dx
69
+ end
70
+
71
+ private
72
+
73
+ def archive()
74
+
33
75
  # archive the weekly planner
34
76
  # e.g. weeklyplanner/2015/wp50.xml
35
77
  d = Date.strptime(@dx.all.first.id, "%Y%m%d")
@@ -58,6 +100,7 @@ class WeeklyPlanner
58
100
  end
59
101
  end
60
102
 
103
+ dx.sort_by! {|x| x.attributes[:id].to_i}
61
104
  dx.save filepath
62
105
 
63
106
  else
@@ -68,36 +111,10 @@ class WeeklyPlanner
68
111
 
69
112
  end
70
113
 
71
- end
72
-
73
- end
74
-
75
- def to_s()
76
- @s
114
+ end
77
115
  end
78
-
79
- private
80
116
 
81
- def create()
82
-
83
- d = DateTime.now
84
-
85
- def ordinal(n)
86
- n.to_s + ( (10...20).include?(n) ? 'th' : \
87
- %w{ th st nd rd th th th th th th }[n % 10] )
88
- end
89
-
90
- a = []
91
- a << "%s, %s %s" % [Date::DAYNAMES[d.wday], ordinal(d.day),
92
- Date::ABBR_MONTHNAMES[d.month]]
93
- a += (d+1).upto(d+6).map {|date| Date::ABBR_DAYNAMES[date.wday] }
94
-
95
- a2 = a.map {|x| "%s\n%s" % [x, '-' * x.length]}
96
- title = File.basename(@filename)
97
- s = title + "\n" + "=" * title.length + "\n\n%s\n\n" % [a2.join("\n\n")]
98
- end
99
-
100
- def create_dx(s)
117
+ def import_to_dx(s)
101
118
 
102
119
  rows = s.split(/.*(?=^[\w, ]+\n\-+)/)
103
120
 
@@ -123,6 +140,49 @@ class WeeklyPlanner
123
140
 
124
141
  end
125
142
 
126
- def parse()
143
+ def dx_to_s(dx)
144
+
145
+ def format_row(heading, content)
146
+ content.prepend "\n\n" unless content.empty?
147
+ "%s\n%s%s" % [heading, '-' * heading.length, content]
148
+ end
149
+
150
+ def ordinal(n)
151
+ n.to_s + ( (10...20).include?(n) ? 'th' : \
152
+ %w{ th st nd rd th th th th th th }[n % 10] )
153
+ end
154
+
155
+ row1 = dx.all.first
156
+ d = Date.strptime(row1.id, "%Y%m%d")
157
+ heading = "%s, %s %s" % [Date::DAYNAMES[d.wday], ordinal(d.day),
158
+ Date::ABBR_MONTHNAMES[d.month]]
159
+ rows = [format_row(heading, row1.x.lines[1..-1].join.strip)]
160
+
161
+ rows += dx.all[1..-1].map do |row|
162
+ date = Date.strptime(row.id, "%Y%m%d")
163
+ dayname = Date::ABBR_DAYNAMES[date.wday]
164
+ format_row dayname, row.x.lines[1..-1].join.strip
165
+ end
166
+
167
+ title = File.basename(@filename)
168
+ title + "\n" + "=" * title.length + "\n\n%s\n\n" % [rows.join("\n\n")]
169
+
127
170
  end
171
+
172
+ def new_dx()
173
+
174
+ dx = Dynarex.new 'sections[title]/section(x)'
175
+
176
+ d = DateTime.now
177
+ dx.title = "Weekly Planner (%s)" % (d).strftime("%d-%b-%Y")
178
+
179
+ (d).upto(d+6) do |date|
180
+
181
+ dx.create({x: date.strftime("# %d-%b-%Y\n\n")}, \
182
+ id: date.strftime("%Y%m%d"))
183
+ end
184
+
185
+ return dx
186
+ end
187
+
128
188
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weekly_planner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  z7gNRJqGU+m6WOC+EaEcNkm4WwRqy2Il3J8DydaFl+h20aqjFe1k7KgLU8qy8jyU
32
32
  FlTqE0DQzwY5Dg==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-12-08 00:00:00.000000000 Z
34
+ date: 2015-12-09 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
metadata.gz.sig CHANGED
Binary file