monthly_planner 0.1.0 → 0.2.0

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: a3fc602f1c0fd7b4811c6e734e9346d95e58fb05
4
- data.tar.gz: bb270b8bbb7f0746b0c80607fa17e06051de4abf
3
+ metadata.gz: f4c824906739e5fe60be57015b323f02cf92987b
4
+ data.tar.gz: cd1fa7fc0e9339f05d1ca3dfddfd36e74db3cd34
5
5
  SHA512:
6
- metadata.gz: ad7a4fc71e41dffd962eb68e5f47e8456ec29858609d6ff8c1cbd6aaebd74fe85132cfbf37b5787f65f8657de7a98908fc0fa399bb9afa410ebf7f1724a12358
7
- data.tar.gz: 00c663bb323a814597b902e4622323f282a676a9833e0337918ca7af2a9f01e7caab7c0d19ca41b16f6f110a6ec77f830f17b7992166cbc4034b168b3a4426d0
6
+ metadata.gz: 74c1e5ac19935ed7521f7549e6ea4be0c137caef931e893bc098d50f3f6328aea964dc792685c65903b79697444a1068160ec5d462b59eb1c2529a38ac2a22e0
7
+ data.tar.gz: 6ab3909c86179ae7a8c584038e2efea871594f9c19515182c176892d5ba3f140e02251969cac48fc1e699f930d3ab7644ac5fcb71b2fb1c080112836bb187160
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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
- @dx = new_dx
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
- rows = ['']
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\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 = %i(itself next_month)\
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monthly_planner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file