monthly_planner 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4c824906739e5fe60be57015b323f02cf92987b
4
- data.tar.gz: cd1fa7fc0e9339f05d1ca3dfddfd36e74db3cd34
3
+ metadata.gz: 580a1fea8fcf9d33782c3dd37d1bc511b8de8076
4
+ data.tar.gz: b7c207d482f9f2afd515fd3e0eac3e61d208b7f6
5
5
  SHA512:
6
- metadata.gz: 74c1e5ac19935ed7521f7549e6ea4be0c137caef931e893bc098d50f3f6328aea964dc792685c65903b79697444a1068160ec5d462b59eb1c2529a38ac2a22e0
7
- data.tar.gz: 6ab3909c86179ae7a8c584038e2efea871594f9c19515182c176892d5ba3f140e02251969cac48fc1e699f930d3ab7644ac5fcb71b2fb1c080112836bb187160
6
+ metadata.gz: 8eaf7dbf857eca23aad06f7967948db46504946f1e10902fa57665f8dfcd7752294b77aa05cc9105a20ae37f84c6364d3642cdf881937728694ef0db0c988c3f
7
+ data.tar.gz: 2db2bbfaa30344b5f8029d4d158e294d5a7c05591bc47588a99a9980ead84eac503b6a99bb8ea14590cc0325351c48b09432fc0c7adc1e842a4cef56144336c2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,13 +4,25 @@
4
4
 
5
5
  require 'date'
6
6
  require 'dynarex'
7
+ require 'chronic'
7
8
  require 'fileutils'
9
+ require 'fuzzy_match'
8
10
 
9
11
 
10
12
  # The MonthlyPlanner gem can:
11
13
  #
12
14
  # * create a new monthly-planner.txt file
13
15
  # * read an existing monthly-planner.txt file
16
+ # * archive and synchronise entries from the monthly-planner with the archive
17
+
18
+
19
+ class RecordX
20
+
21
+ def date
22
+ Chronic.parse(@date)
23
+ end
24
+
25
+ end
14
26
 
15
27
  class MonthlyPlanner
16
28
 
@@ -25,6 +37,7 @@ class MonthlyPlanner
25
37
  if File.exists?(fpath) then
26
38
 
27
39
  @dx = import_to_dx(File.read(fpath))
40
+ sync_archive(@dx.all)
28
41
  else
29
42
  @dx = new_dx
30
43
  end
@@ -49,13 +62,9 @@ class MonthlyPlanner
49
62
  private
50
63
 
51
64
  def dx_to_s(dx)
52
-
53
- rows = dx.all.map do |x|
54
- %i(date time desc).map{|y| !x[y].empty? ? x[y] + ' ' : '' }.join
55
- end
56
-
65
+
57
66
  title = File.basename(@filename)
58
- title + "\n" + "=" * title.length + "\n\n%s\n\n" % [rows.join("\n")]
67
+ title + "\n" + "=" * title.length + "\n\n%s\n\n" % [dx.to_s(header: false)]
59
68
 
60
69
  end
61
70
 
@@ -86,8 +95,7 @@ class MonthlyPlanner
86
95
 
87
96
  def new_dx()
88
97
 
89
- dx = Dynarex.new 'month[title]/day(date, time, desc, uid)',
90
- default_key: :uid
98
+ dx = Dynarex.new 'month[title]/day(date, time, desc)', default_key: :uid
91
99
 
92
100
  d = DateTime.now.to_date
93
101
  title = [d, d.next_month].map {|x| x.strftime("%b")}.join(' - ')
@@ -95,5 +103,59 @@ class MonthlyPlanner
95
103
 
96
104
  return dx
97
105
  end
106
+
107
+
108
+ def sync_archive(dxrows=@dx.all)
109
+
110
+ # group by month
111
+ a = dxrows.group_by {|x| x.date.strftime("%b").downcase}
112
+
113
+ # add the file to the archive.
114
+
115
+ a.each do |month, days|
116
+
117
+ d = days.first.date
118
+
119
+ archive_path = File.join(@path, d.year.to_s, month)
120
+ FileUtils.mkdir_p archive_path
121
+ filepath = File.join archive_path, 'mp.xml'
122
+
123
+ if File.exists? filepath then
124
+
125
+ dx2 = Dynarex.new filepath
126
+
127
+ days.each do |day|
128
+
129
+ # determine if the entry already exists in the Dynarex doc
130
+
131
+ rows = dx2.to_s(header: false).lines.map(&:chomp)
132
+ fm = FuzzyMatch.new rows
133
+ found, score = fm.find_with_score %i(date time desc)\
134
+ .map {|y| day[y]}.join ' '
135
+ if score < 0.7 then
136
+ dx2.create(day)
137
+ else
138
+ i = rows.index found
139
+ dx2.update(dx2.all[i].id, day)
140
+ end
141
+
142
+ end
143
+
144
+
145
+ else
146
+
147
+ # if the index.xml file doesn't exist just save them
148
+
149
+ dx2 = Dynarex.new dx.schema
150
+ dx2.title = "Monthly Planner #{month.capitalize}-#{d.year}"
151
+ dx2.import days
152
+
153
+ end
154
+
155
+ dx2.save filepath
156
+
157
+ end
158
+
159
+ end
98
160
 
99
161
  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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  La10JAgwh3I97hV0e0ftxKgM9wPTv/1NX1ejKg4fj4f68cTSVJZTNJFFM2ljPCK1
32
32
  94ClrbJHIurLOQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2016-07-22 00:00:00.000000000 Z
34
+ date: 2016-07-23 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: '1.7'
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- version: 1.7.9
45
+ version: 1.7.11
46
46
  type: :runtime
47
47
  prerelease: false
48
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -52,7 +52,47 @@ dependencies:
52
52
  version: '1.7'
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 1.7.9
55
+ version: 1.7.11
56
+ - !ruby/object:Gem::Dependency
57
+ name: fuzzy_match
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.1'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.1.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.1'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.1.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: chronic
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.10.2
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '0.10'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.10.2
56
96
  description:
57
97
  email: james@r0bertson.co.uk
58
98
  executables: []
metadata.gz.sig CHANGED
Binary file