polyrex-calendar 0.1.24 → 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: d1cda2f751877893ac77af61f539c15448642dc4
4
- data.tar.gz: 93e962b6c459b71da59d07ae4c37d31d44d61e76
3
+ metadata.gz: c5b7f2adb9120d8bb6f30118816a105abb7321d5
4
+ data.tar.gz: 7d8db19931ccce31286d9d10962e75bf26f77554
5
5
  SHA512:
6
- metadata.gz: a46040bfff78be573fb1e8999001e4605d75bd4ba0a13fe47e8c478f8a14b7028106706e55a71bbd9e87cb6e03f46540262aff5376e1c008aee687b25a7f14ec
7
- data.tar.gz: cdbe56b3c4f8a54a12c13dfa3275499039b5df94aae28e1d659dbf8e594b0a2c65a6ea913c6bd63ae3abf1146cfcce56b4ece491b1c0979a869557f6687064ed
6
+ metadata.gz: f7f017e63343dce72c18ba5d7cc7f82c334f9e0eb6d155a3a037ab944c749fb7010d7fb35540ef99a0836a4a57871488e3802267ee6429f66b88335b2fc29597
7
+ data.tar.gz: 971706fa487574ebb81cff54bff62750bf880cc95ebb412b000dfd191cfd3f70254d645682b5817606e84c7a805573afe674f21c353ff9d072e7adb5b92a88f1
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,6 +6,7 @@ require 'polyrex'
6
6
  require 'date'
7
7
  require 'nokogiri'
8
8
  require 'chronic_duration'
9
+ require 'chronic_cron'
9
10
 
10
11
  MINUTE = 60
11
12
  HOUR = MINUTE * 60
@@ -14,9 +15,21 @@ WEEK = DAY * 7
14
15
  MONTH = DAY * 30
15
16
 
16
17
 
18
+
19
+ h = {
20
+ calendar: 'calendar[year]',
21
+ month: 'month[n, title]',
22
+ week: 'week[n]',
23
+ day: 'day[n, event, date, bankholiday, title]',
24
+ entry: 'entry[time_start, time_end, duration, title]'
25
+ }
26
+ visual_schema = %i(calendar month week day entry).map{|x| h[x]}.join '/'
27
+ PolyrexObjects.new(visual_schema)
28
+
17
29
  module LIBRARY
18
30
 
19
31
  def fetch_file(filename)
32
+
20
33
  lib = File.dirname(__FILE__)
21
34
  File.read filename
22
35
  end
@@ -30,137 +43,147 @@ module LIBRARY
30
43
  end
31
44
  end
32
45
 
33
- class PolyrexCalendar
46
+ class Polyrex
34
47
  include LIBRARY
35
48
 
36
- attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
37
- attr_reader :day
38
-
39
- def initialize(calendar_file=nil, options={})
49
+ attr_accessor :xslt, :css_layout, :css_style, :filename
40
50
 
41
- opts = {year: Time.now.year.to_s}.merge(options)
42
- @year = opts[:year]
51
+ def inspect()
52
+ "#<Polyrex:%s" % __id__
53
+ end
43
54
 
44
- @schema = 'calendar[year]/month[no,title,year]/' + \
45
- 'week[no, rel_no, mon, label]/day[wday, xday, title, event, date, ' + \
46
- 'ordinal, overlap, bankholiday]/' + \
47
- 'entry[time_start, time_end, duration, title]'
55
+ def to_webpage()
48
56
 
49
- if calendar_file then
50
- @polyrex = Polyrex.new calendar_file
51
- @id = @polyrex.id_counter
57
+ year_xsl = fetch_file self.xslt
58
+ year_layout_css = fetch_file self.css_layout
59
+ year_css = fetch_file self.css_style
52
60
 
53
- @day = {}
54
- @polyrex.records.each_with_index do |month,m|
55
- month.records.each_with_index do |weeks,w|
56
- weeks.records.each_with_index do|d,i|
57
- @day[Date.parse(d.date)] = [m,w,i]
58
- end
59
- end
60
- end
61
+ File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
62
+ File.open(self.xslt,'w'){|f| f.write year_xsl }
63
+ #html = Rexslt.new(month_xsl, self.to_xml).to_xml
61
64
 
62
- else
63
- @id = '1'
64
- generate_calendar
65
- end
65
+ html = generate_webpage self.to_xml, year_xsl
66
+ {self.filename => html,
67
+ self.css_layout => year_layout_css, self.css_style => year_css}
66
68
 
67
- @xsl = fetch_file 'calendar.xsl'
68
- @css = fetch_file 'layout.css'
69
+ end
70
+ end
71
+
72
+ class PolyrexObjects::Month
73
+ include LIBRARY
69
74
 
70
- Polyrex.class_eval do
71
- include LIBRARY
75
+ attr_accessor :xslt, :css_layout, :css_style
72
76
 
73
- attr_accessor :xslt, :css_layout, :css_style, :filename
77
+ def inspect()
78
+ "#<PolyrexObjects::Month:%s" % __id__
79
+ end
74
80
 
75
- def inspect()
76
- "#<Polyrex:%s" % __id__
77
- end
81
+ def to_webpage()
78
82
 
79
- def to_webpage()
83
+ month_xsl = fetch_file self.xslt
84
+ month_layout_css = fetch_file self.css_layout
85
+ month_css = fetch_file self.css_style
80
86
 
81
- year_xsl = fetch_file self.xslt
82
- year_layout_css = fetch_file self.css_layout
83
- year_css = fetch_file self.css_style
87
+ File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
88
+ File.open('month.xsl','w'){|f| f.write month_xsl }
89
+ #html = Rexslt.new(month_xsl, self.to_xml).to_xml
84
90
 
85
- File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
86
- File.open(self.xslt,'w'){|f| f.write year_xsl }
87
- #html = Rexslt.new(month_xsl, self.to_xml).to_xml
91
+ # add a css selector for the current day
92
+ date = Time.now.strftime("%Y-%b-%d")
93
+ doc = Rexle.new self.to_xml
94
+ e = doc.root.element("records/week/records/day/summary[date='#{date}']")
95
+ e.add Rexle::Element.new('css_style').add_text('selected')
88
96
 
89
- html = generate_webpage self.to_xml, year_xsl
90
- {self.filename => html,
91
- self.css_layout => year_layout_css, self.css_style => year_css}
97
+ html = generate_webpage doc.xml, month_xsl
98
+ {self.title.downcase[0..2] + '_calendar.html' => html,
99
+ self.css_layout => month_layout_css, self.css_style => month_css}
100
+ end
101
+
102
+ def wk(n)
103
+ self.records[n-1]
104
+ end
105
+ end
92
106
 
93
- end
94
-
95
- end
107
+ class PolyrexObjects::Week
108
+ include LIBRARY
96
109
 
97
- PolyrexObjects::Month.class_eval do
98
- include LIBRARY
110
+ def inspect()
111
+ "#<PolyrexObjects::Week:%s" % __id__
112
+ end
113
+
114
+ def to_webpage()
99
115
 
100
- attr_accessor :xslt, :css_layout, :css_style
116
+ week_xsl = fetch_file 'week_calendar.xsl'
117
+ week_layout_css = fetch_file 'week_layout.css'
118
+ week_css = fetch_file 'week.css'
101
119
 
102
- def inspect()
103
- "#<PolyrexObjects::Month:%s" % __id__
104
- end
120
+ File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
121
+ File.open('week.xsl','w'){|f| f.write week_xsl }
122
+ #html = Rexslt.new(week_xsl, self.to_xml).to_xml
123
+ #html = xsltproc 'week_calendar.xsl', self.to_xml
105
124
 
106
- def to_webpage()
107
-
108
- month_xsl = fetch_file self.xslt
109
- month_layout_css = fetch_file self.css_layout
110
- month_css = fetch_file self.css_style
111
-
112
- File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
113
- File.open('month.xsl','w'){|f| f.write month_xsl }
114
- #html = Rexslt.new(month_xsl, self.to_xml).to_xml
115
-
116
- # add a css selector for the current day
117
- date = Time.now.strftime("%Y-%b-%d")
118
- doc = Rexle.new self.to_xml
119
- e = doc.root.element("records/week/records/day/summary[date='#{date}']")
120
- e.add Rexle::Element.new('css_style').add_text('selected')
121
-
122
- html = generate_webpage doc.xml, month_xsl
123
- {self.title.downcase[0..2] + '_calendar.html' => html,
124
- self.css_layout => month_layout_css, self.css_style => month_css}
125
- end
126
-
127
- def wk(n)
128
- self.records[n-1]
129
- end
130
- end
131
-
132
- PolyrexObjects::Week.class_eval do
133
- include LIBRARY
125
+ # add a css selector for the current day
126
+ date = Time.now.strftime("%Y-%b-%d")
127
+ doc = Rexle.new self.to_xml
128
+ e = doc.root.element("records/day/summary[date='#{date}']")
134
129
 
135
- def inspect()
136
- "#<PolyrexObjects::Week:%s" % __id__
137
- end
138
-
139
- def to_webpage()
130
+ e.add Rexle::Element.new('css_style').add_text('selected')
131
+
132
+ html = generate_webpage doc.xml, week_xsl
133
+ {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
134
+ 'week.css' => week_css}
135
+ end
136
+ end
137
+
138
+ class PolyrexCalendar
139
+ include LIBRARY
140
+
141
+ attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
142
+ attr_reader :day
143
+
144
+ def initialize(calendar_file=nil, options={})
140
145
 
141
- week_xsl = fetch_file 'week_calendar.xsl'
142
- week_layout_css = fetch_file 'week_layout.css'
143
- week_css = fetch_file 'week.css'
146
+ opts = {year: Time.now.year.to_s}.merge(options)
147
+ @year = opts[:year]
148
+
149
+ @h = {
150
+ calendar: 'calendar[year]',
151
+ month: 'month[n, title]',
152
+ week: 'week[n]',
153
+ day: 'day[n, event, date, bankholiday]',
154
+ entry: 'entry[time_start, time_end, duration, title]'
155
+ }
156
+ schema = %i(calendar month day entry).map{|x| @h[x]}.join '/'
157
+ #@visual_schema = %i(calendar month week day entry).map{|x| @h[x]}.join '/'
158
+
159
+
160
+ if calendar_file then
161
+ @polyrex = Polyrex.new calendar_file
162
+ @id = @polyrex.id_counter
163
+
164
+ else
165
+ @id = '1'
166
+ # generate the calendar
144
167
 
145
- File.open('self.xml','w'){|f| f.write self.to_xml pretty: true}
146
- File.open('week.xsl','w'){|f| f.write week_xsl }
147
- #html = Rexslt.new(week_xsl, self.to_xml).to_xml
148
- #html = xsltproc 'week_calendar.xsl', self.to_xml
168
+ a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
149
169
 
150
- # add a css selector for the current day
151
- date = Time.now.strftime("%Y-%b-%d")
152
- doc = Rexle.new self.to_xml
153
- e = doc.root.element("records/day/summary[date='#{date}']")
170
+ @polyrex = Polyrex.new(schema, id_counter: @id)
171
+ @polyrex.summary.year = @year
154
172
 
155
- e.add Rexle::Element.new('css_style').add_text('selected')
173
+ a.group_by(&:month).each do |month, days|
156
174
 
157
- html = generate_webpage doc.xml, week_xsl
158
- {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
159
- 'week.css' => week_css}
175
+ @polyrex.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create|
176
+ days.each do |x|
177
+ create.day n: x.day, wday: x.wday, date: x.strftime("%Y-%b-%d")
178
+ end
179
+ end
160
180
  end
161
-
181
+
162
182
  end
163
-
183
+
184
+ @xsl = fetch_file 'calendar.xsl'
185
+ @css = fetch_file 'layout.css'
186
+
164
187
  end
165
188
 
166
189
  def to_a()
@@ -228,8 +251,7 @@ class PolyrexCalendar
228
251
 
229
252
  records.delete
230
253
 
231
- h = PolyrexObjects.new(@schema).to_h
232
- pxmonth = h['Month'].new doc_month.root
254
+ pxmonth = PolyrexObjects::Month.new doc_month.root
233
255
 
234
256
  a = days_in_month
235
257
  i = a[0].text('summary/wday').to_i
@@ -244,12 +266,13 @@ class PolyrexCalendar
244
266
 
245
267
  a2.each_slice(7) do |days_in_week|
246
268
 
247
- pxweek = h['Week'].new Rexle.new('<week><summary/><records/></week>').root
269
+ pxweek = PolyrexObjects::Week.new \
270
+ Rexle.new('<week><summary/><records/></week>').root
248
271
 
249
272
  days_in_week.each do |day|
250
273
 
251
274
  day = Rexle.new("<day><summary/><records/></day>") unless day
252
- pxweek.add h['Day'].new(day.root)
275
+ pxweek.add PolyrexObjects::Day.new(day.root)
253
276
  end
254
277
 
255
278
  pxmonth.add pxweek
@@ -318,7 +341,7 @@ class PolyrexCalendar
318
341
 
319
342
  week = doc_week.root.element 'records'
320
343
  days_in_week.each {|day| week.add day }
321
- PolyrexObjects.new(@schema).to_h['Week'].new doc_week.root
344
+ PolyrexObjects::Week.new doc_week.root
322
345
 
323
346
  end
324
347
 
@@ -339,10 +362,10 @@ class PolyrexCalendar
339
362
  dynarex.flat_records.each do |event|
340
363
 
341
364
  dt = DateTime.parse(event[:date])
342
- m,w,i = @day[dt.to_date]
365
+ m, d = dt.month, dt.day
343
366
  record = {title: title, time_start: time_start}
344
367
 
345
- @polyrex.records[m].week[w].day[i].create.entry record
368
+ @polyrex.records[m-1].day[d-1].create.entry record
346
369
  end
347
370
  end
348
371
 
@@ -353,8 +376,8 @@ class PolyrexCalendar
353
376
  dynarex.flat_records.each do |event|
354
377
 
355
378
  dt = DateTime.parse(event[:date])
356
- m,w,i = @day[dt.to_date]
357
- @polyrex.records[m].week[w].day[i].method(daytype).call event[:title]
379
+ m, d = dt.month, dt.day
380
+ @polyrex.records[m-1].day[d-1].method(daytype).call event[:title]
358
381
  end
359
382
  end
360
383
 
@@ -420,97 +443,10 @@ class PolyrexCalendar
420
443
  end
421
444
 
422
445
  end
423
-
424
-
425
- def generate_calendar()
426
-
427
- a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
428
-
429
- months = a.group_by(&:month).map do |key, month|
430
-
431
- i = month.index(month.detect{|x| x.wday == 0})
432
- unless i == 0 then
433
- weeks = [month.slice!(0,i)] + month.each_slice(7).to_a
434
- (weeks[0] = ([nil] * 6 + weeks[0]).slice(-7..-1))
435
- else
436
- weeks = month.each_slice(7).to_a
437
- end
438
-
439
- weeks[-1] = (weeks[-1] + [nil] * 6 ).slice(0,7) if weeks[-1].length < 7
440
-
441
- weeks
442
- end
443
-
444
- @day = {}
445
- months.each_with_index do |month,m|
446
- month.each_with_index do |weeks,w|
447
- weeks.each_with_index{|d,i| @day[d] = [m,w,i]}
448
- end
449
- end
450
-
451
- @a = months
452
-
453
- @polyrex = Polyrex.new(@schema, id_counter: @id)
454
- year_start = months[0][0][-1]
455
- @polyrex.summary.year = @year
456
- old_year_week = (year_start - 7).cweek
457
-
458
- week_i = 1
459
-
460
- months.each_with_index do |month,i|
461
- month_name = Date::MONTHNAMES[i+1]
462
- @polyrex.create.month no: (i+1).to_s, title: month_name, year: @year do |create|
463
- month.each_with_index do |week,j|
464
-
465
- # jr241213 week_s = (week_i == 0 ? old_year_week : week_i).to_s
466
- week_s = week_i.to_s
467
-
468
- if week[0].nil? then
469
- label = Date::MONTHNAMES[(i > 0 ? i : 12)] + " - " + month_name
470
- end
471
-
472
- if week[-1].nil? then
473
- label = month_name + " - " + Date::MONTHNAMES[(i+2 <= 12 ? i+2 : 1)]
474
- end
475
-
476
-
477
- week_record = {
478
- rel_no: (j+1).to_s,
479
- no: week_s,
480
- mon: month_name,
481
- label: label
482
- }
483
-
484
- create.week week_record do |create|
485
- week.each_with_index do |day, k|
486
-
487
- # if it's a day in the month then ...
488
- if day then
489
- x = day
490
- week_i += 1 if x.wday == 6
491
- h = {wday: x.wday.to_s, xday: x.day.to_s, \
492
- title: Date::DAYNAMES[k], date: x.strftime("%Y-%b-%d"), \
493
- ordinal: ordinal(x.day.to_i)}
494
- else
495
- #if blank find the nearest date in the week and calculate this date
496
- # check right and if nothing then it's at the end of the month
497
- x = week[-1] ? (week[-1] - (7-(k+1))) : week[0] + k
498
- h = {wday: x.wday.to_s, xday: x.day.to_s, \
499
- title: Date::DAYNAMES[k], date: x.strftime("%Y-%b-%d"), \
500
- ordinal: ordinal(x.day.to_i), overlap: 'true'}
501
- end
502
-
503
- create.day(h)
504
- end
505
- end
506
- end
507
- end
508
- end
509
-
510
- end
511
-
512
- def ordinal
513
- ( (10...20).include?(self) ? 'th' : %w{ th st nd rd th th th th th th }[self % 10] )
446
+
447
+ def ordinal(val)
448
+ (10...20).include?(val) ? \
449
+ 'th' : %w{ th st nd rd th th th th th th }[val % 10]
514
450
  end
515
451
 
516
452
  def slotted_sort(a)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polyrex-calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -29,7 +29,7 @@ cert_chain:
29
29
  CIpMEIXEnQwmcmWL07xvpUquKTab0tCXtmcfjr74KP2KCm5guZyxeXaj9lD1OrnC
30
30
  Kgt/mRI2beG8K7QY81GGMsQjiG95Dcko
31
31
  -----END CERTIFICATE-----
32
- date: 2014-01-15 00:00:00.000000000 Z
32
+ date: 2014-01-17 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: polyrex
@@ -73,6 +73,20 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: chronic_cron
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
76
90
  description:
77
91
  email: james@r0bertson.co.uk
78
92
  executables: []
metadata.gz.sig CHANGED
Binary file