weekly_planner 0.2.1 → 0.3.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: c449a1287de09f9dc3a8eeac9bea5320af286845
4
- data.tar.gz: 570e60554cb6693fc0e7fd85540f2bf6a2e8c671
3
+ metadata.gz: b57d541f09b80f9d9e95cf409605e7d50885af13
4
+ data.tar.gz: 3a62786aa9785aab297dee4fe0268ba9dd94d7a3
5
5
  SHA512:
6
- metadata.gz: 7257b020f03bac607a410c6b990bca34d875b239feeaf92a24e67019840c915f260cb6c99c2435be1943577194ef796eb8123fbb2842d7f92d8b1735c24b0775
7
- data.tar.gz: 537d4104dbe2edb2b7878cf63cb08fede7a7915ced7636a942be68eb987c9217524fb8be4bc62c992629ee1c57034afc5bfa71269d7ce8b192d828f184ec6f5a
6
+ metadata.gz: b2867a08a2201062a6912fec53090e29b40e15970bf3c07817edada0b9b97a044efa6793740270dee29b242c13ee6eab236d9e4b531571341d8921bf78f20b99
7
+ data.tar.gz: 828639a10f95f3b4aae7929c8378a4f8a1675354df0f1d3eaecf1ab5d6a196091ba8f9b808867a99c038bca06050f0be6d9ce13297468e774fc721cbb169f366
checksums.yaml.gz.sig CHANGED
Binary file
@@ -7,6 +7,14 @@ require 'dynarex'
7
7
  require 'fileutils'
8
8
 
9
9
 
10
+ class RecordX
11
+
12
+ def last_modified
13
+ v = @last_modified
14
+ v.empty? ? nil : Date.parse(v)
15
+ end
16
+
17
+ end
10
18
 
11
19
  class WeeklyPlanner
12
20
 
@@ -19,10 +27,10 @@ class WeeklyPlanner
19
27
  fpath = File.join(path, filename)
20
28
 
21
29
  if File.exists?(fpath) then
22
-
23
- s = File.read(fpath)
24
- @dx = import_to_dx(s)
25
- archive()
30
+
31
+ dx = import_to_dx(File.read(fpath))
32
+ @dx = refresh File.join(path, filename.sub(/\.txt$/,'.xml')), dx
33
+ sync_archive()
26
34
 
27
35
  # purge any past dates
28
36
  while Date.parse(@dx.all.first.id, "%Y%m%d") != DateTime.now.to_date \
@@ -43,6 +51,8 @@ class WeeklyPlanner
43
51
  id: (date + i).strftime("%Y%m%d"))
44
52
  end
45
53
 
54
+ sync_archive @dx.all[-(len)..-1]
55
+
46
56
  end
47
57
 
48
58
  else
@@ -59,8 +69,9 @@ class WeeklyPlanner
59
69
 
60
70
  s = File.basename(filename) + "\n" + dx_to_s(@dx).lines[1..-1].join
61
71
  File.write File.join(@path, filename), s
72
+ @dx.save File.join(@path, filename.sub(/\.txt$/,'.xml'))
62
73
 
63
- archive()
74
+ sync_archive()
64
75
 
65
76
  end
66
77
 
@@ -70,15 +81,15 @@ class WeeklyPlanner
70
81
 
71
82
  private
72
83
 
73
- def archive()
84
+ def sync_archive(dxrows=@dx.all)
74
85
 
75
86
  # archive the weekly planner
76
87
  # e.g. weeklyplanner/2015/wp50.xml
77
- d = Date.strptime(@dx.all.first.id, "%Y%m%d")
88
+ d = Date.strptime(dxrows.first.id, "%Y%m%d")
78
89
  archive_path = File.join(@path, d.year.to_s)
79
90
  FileUtils.mkdir_p archive_path
80
91
 
81
- a = @dx.all.partition {|x| Date.strptime(x.id, "%Y%m%d").cweek == d.cweek }
92
+ a = dxrows.partition {|x| Date.strptime(x.id, "%Y%m%d").cweek == d.cweek }
82
93
 
83
94
  a.each do |rows|
84
95
 
@@ -94,7 +105,20 @@ class WeeklyPlanner
94
105
  record = dx.find_by_id row.id
95
106
 
96
107
  if record then
97
- record.x = row.x unless record.x == row.x
108
+
109
+ if record.x != row.x then
110
+
111
+ if record.last_modified.nil? then
112
+ record.x = row.x
113
+ elsif row.last_modified.nil?
114
+ row.x = record.x
115
+ elsif row.last_modified > record.last_modified
116
+ record.x = row.x
117
+ else
118
+ row.x = record.x
119
+ end
120
+ end
121
+
98
122
  else
99
123
  dx.create row
100
124
  end
@@ -184,5 +208,17 @@ class WeeklyPlanner
184
208
 
185
209
  return dx
186
210
  end
211
+
212
+ def refresh(dxfilepath, latest_dx)
213
+
214
+ dx = Dynarex.new File.read(dxfilepath)
215
+
216
+ dx.all.each.with_index do |row, i|
217
+ row.x = latest_dx.all[i].x if row.x != latest_dx.all[i].x
218
+ end
219
+
220
+ dx
221
+
222
+ end
187
223
 
188
224
  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.1
4
+ version: 0.3.0
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-09 00:00:00.000000000 Z
34
+ date: 2015-12-10 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: dynarex
metadata.gz.sig CHANGED
Binary file