polyrex-calendar 0.3.11 → 0.5.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: a12d35568f6415a47e583e6991deadda6ad821aa
4
- data.tar.gz: 492af65848a1efa54b982bd933aae06b3d5b1c68
3
+ metadata.gz: bce4882cc2ad150e9fb2edd2d6a786896b5ebeb9
4
+ data.tar.gz: 3451f7a0e86515f3186875b6c3026f42cd94fcbb
5
5
  SHA512:
6
- metadata.gz: e146ccf872111f38f8f0b7512baac6d776755409fb288f178564abb1ee8f590c9369c09a7c007d56d6e3116158119c073683665ea4804d26de699da19e113448
7
- data.tar.gz: e5020e116c468e67bea52bf40ea4155f3d8c20ba582b8b91ed4893b86e2f08ec6d4d90c13c1a70b77decd27626853bfcc7d8a43e5f366af772e2d75fd0f4f6d7
6
+ metadata.gz: b6f54c2840a6833dc3720cb8c331558b3baca82250606969ea3bea904a2773281ea8463318c184c4192a873b2ac29e50263c9fd535a7bc277e0fff7beb630a8a
7
+ data.tar.gz: 45b084ec740fdd9163163e22aff6a32ed13a0b83f6ec7fc7d05b9f2316eb69c7120bef21fabe59ec9e0cabf2f3cccdeb405ad8532ad61c75b986685e2d6a2bc4
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- K������خ' +[�652GQ����9�*��
2
- ������E;r�CAEE���/�޾ΧI� �Jf���A�$Ԕ����0�Ζ��*��r�e�M���ˮ{��p�r>h�r&���p��������r'����T���e5k�����ɂ����r��J7�%�/��+��yHj�n��W�W�/�io_�@E8�`ݜ��'ɷ�4m�ݑ��T�_��U�QwB��,����I$��#�)+�������E
1
+ F�Ȭ2泚8���wb$�9r�_%HX��O��)��@i׵i=�IɊ�疓 @������k�P�.G�~q[�pgM �n~��X:����o� E�e�x� VH����r��j��̱Ak���P�ž����W��U�����{+�0J��L� �\��oqS#�h��΃]�޻B��:��J;��\mbe#x�t�������-+�����G�!�[`�=#� (U��~��1�5wGQ������^I�A7AlĈw!,l
@@ -2,230 +2,65 @@
2
2
 
3
3
  # file: polyrex-calendar.rb
4
4
 
5
- require 'polyrex'
6
- require 'date'
7
- require 'nokogiri'
8
- require 'chronic_duration'
9
- require 'chronic_cron'
10
- require 'rxfhelper'
5
+ require 'px-calendarbase'
11
6
 
12
7
 
13
- MONTH = DAY * 30
14
-
15
-
16
- h = {
17
- calendar: 'calendar[year]',
18
- month: 'month[n, title]',
19
- week: 'week[n, mon, no, label]',
20
- day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
21
- entry: 'entry[time_start, time_end, duration, title]'
22
- }
23
- visual_schema = h.values.join '/'
24
- PolyrexObjects.new(visual_schema)
25
-
26
- module LIBRARY
27
-
28
- def fetch_file(filename)
29
-
30
- lib = File.dirname(__FILE__)
31
- File.read filename
32
-
33
- end
34
-
35
- def generate_webpage(xml, xsl)
36
-
37
- # transform the xml to html
38
- doc = Nokogiri::XML(xml)
39
- xslt = Nokogiri::XSLT(xsl)
40
- xslt.transform(doc).to_s
41
- end
42
-
43
- def read(s)
44
- RXFHelper.read(s).first
45
- end
46
- end
47
-
48
- class Polyrex
49
- include LIBRARY
50
-
51
- attr_accessor :xslt, :css_layout, :css_style, :filename
52
-
53
- def inspect()
54
- "#<Polyrex:%s" % __id__
55
- end
56
-
57
- def to_webpage()
58
-
59
- year_xsl = self.xslt ? read(self.xslt) : fetch_file(self.xslt)
60
- year_layout_css = fetch_file self.css_layout
61
- year_css = fetch_file self.css_style
62
- File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
63
- File.open(self.xslt,'w'){|f| f.write year_xsl }
64
- #html = Rexslt.new(month_xsl, self.to_xml).to_xml
65
-
66
- html = generate_webpage self.to_xml, year_xsl
67
- {self.filename => html,
68
- self.css_layout => year_layout_css, self.css_style => year_css}
69
-
70
- end
71
- end
72
-
73
- class PolyrexObjects::Month
74
- include LIBRARY
75
-
76
- attr_accessor :xslt, :css_layout, :css_style
77
-
78
- def inspect()
79
- "#<PolyrexObjects::Month:%s" % __id__
80
- end
81
-
82
- def to_webpage()
83
-
84
- month_xsl = fetch_file self.xslt
85
- month_layout_css = fetch_file self.css_layout
86
- month_css = fetch_file self.css_style
87
-
88
- # add a css selector for the current day
89
- date = Time.now.strftime("%Y-%b-%d")
90
-
91
- e = self.element("records/week/records/day/summary[sdate='#{date}']")
92
- e.attributes[:class] = 'selected' if e
93
-
94
- File.write 'self.xml', self.to_xml(pretty: true)
95
- File.write 'month.xsl', month_xsl
96
-
97
-
98
- html = generate_webpage self.to_xml, month_xsl
99
- {self.title.downcase[0..2] + '_calendar.html' => html,
100
- self.css_layout => month_layout_css, self.css_style => month_css}
101
- end
8
+ class PolyrexObjects
102
9
 
103
- def wk(n)
104
- self.records[n-1]
105
- end
106
- end
107
-
108
- class PolyrexObjects::Week
109
- include LIBRARY
110
-
111
- def inspect()
112
- "#<PolyrexObjects::Week:%s" % __id__
10
+ class Month
11
+
12
+ def wk(n)
13
+ self.records[n-1]
14
+ end
113
15
  end
114
-
115
- def to_webpage()
116
-
117
- week_xsl = fetch_file 'week_calendar.xsl'
118
- week_layout_css = fetch_file 'week_layout.css'
119
- week_css = fetch_file 'week.css'
120
16
 
121
- File.write 'self.xml', self.to_xml(pretty: true)
122
- File.write 'week.xsl', week_xsl
17
+ class Week
18
+
19
+ def to_webpage()
123
20
 
124
- # add a css selector for the current day
125
- date = Time.now.strftime("%Y-%b-%d")
21
+ week_xsl = fetch_file 'week_calendar.xsl'
22
+ week_layout_css = fetch_file 'week_layout.css'
23
+ week_css = fetch_file 'week.css'
126
24
 
127
- e = self.element("records/day/summary[sdate='#{date}']")
128
- e.attributes[:class] = 'selected' if e
25
+ File.write 'self.xml', self.to_xml(pretty: true)
26
+ File.write 'week.xsl', week_xsl
27
+ #html = Rexslt.new(week_xsl, self.to_xml).to_xml
28
+ #html = xsltproc 'week_calendar.xsl', self.to_xml
129
29
 
30
+ # add a css selector for the current day
31
+ date = Time.now.strftime("%Y-%b-%d")
130
32
 
131
- html = generate_webpage self.to_xml, week_xsl
132
- {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
133
- 'week.css' => week_css}
134
- end
135
- end
33
+ e = self.element("records/day/summary[sdate='#{date}']")
34
+ e.attributes[:class] = 'selected' if e
136
35
 
137
- class PolyrexObjects::Day
138
36
 
139
- def date()
140
- Date.parse(self.sdate)
37
+ html = generate_webpage self.to_xml, week_xsl
38
+ {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
39
+ 'week.css' => week_css}
40
+ end
141
41
  end
142
42
 
143
- def wday()
144
- self.date.wday
145
- end
146
43
 
147
- def day()
148
- self.date.day
149
- end
150
44
  end
151
45
 
152
- class PolyrexCalendar
153
- include LIBRARY
154
-
155
- attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
156
- attr_reader :day
46
+ class PolyrexCalendar < PolyrexCalendarBase
157
47
 
158
48
  def initialize(calendar_file=nil, options={})
159
49
 
160
- opts = {year: Time.now.year.to_s}.merge(options)
161
- @year = opts[:year]
162
-
163
- h = {
164
- calendar: 'calendar[year]',
165
- month: 'month[n, title]',
166
- week: 'week[n]',
167
- day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
168
- entry: 'entry[time_start, time_end, duration, title]'
169
- }
170
- @schema = %i(calendar month day entry).map{|x| h[x]}.join '/'
171
- @visual_schema = h.values.join '/'
172
-
173
-
174
- if calendar_file then
175
- @polyrex = Polyrex.new calendar_file
176
- @id = @polyrex.id_counter
177
-
178
- else
179
- @id = '1'
180
- # generate the calendar
181
-
182
- a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
183
-
184
- @polyrex = Polyrex.new(@schema, id_counter: @id)
185
- @polyrex.summary.year = @year
186
-
187
- a.group_by(&:month).each do |month, days|
188
-
189
- @polyrex.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create|
190
- days.each do |x|
191
- create.day sdate: x.strftime("%Y-%b-%d"), xday: x.day.to_s, title: Date::DAYNAMES[x.wday]
192
- end
193
- end
194
- end
195
-
196
- end
197
-
198
- visual_schema = h.values.join '/'
199
- PolyrexObjects.new(visual_schema)
50
+ super(calendar_file, options)
200
51
 
201
52
  @xsl = fetch_file 'calendar.xsl'
202
53
  @css = fetch_file 'layout.css'
203
54
 
204
55
  end
205
56
 
206
- def to_a()
207
- @a
208
- end
209
-
210
- def to_xml()
211
- @polyrex.to_xml pretty: true
212
- end
213
-
214
- def import_events(objx)
215
- @id = @polyrex.id_counter
216
- method('import_'.+(objx.class.to_s.downcase).to_sym).call(objx)
217
- self
218
- end
219
-
220
- alias import! import_events
221
-
222
57
  def inspect()
223
58
  %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">)
224
59
  end
225
60
 
226
61
  def kitchen_planner()
227
62
 
228
- px = @polyrex
63
+ px = @calendar
229
64
 
230
65
  # add a css selector for the current day
231
66
  date = DateTime.now.strftime("%Y-%b-%d")
@@ -285,7 +120,6 @@ class PolyrexCalendar
285
120
 
286
121
  r
287
122
 
288
-
289
123
  end
290
124
 
291
125
  pxmonth.xslt = 'monthday_calendar.xsl'
@@ -320,37 +154,11 @@ class PolyrexCalendar
320
154
  end
321
155
 
322
156
  end
323
- def month_day()
324
- end
325
-
326
- def months
327
- @polyrex.records
328
- end
329
-
330
- def parse_events(list)
331
157
 
332
- polyrex = Polyrex.new('events/dayx[date, title]/entryx[start_time, end_time,' + \
333
- ' duration, title]')
334
-
335
- polyrex.format_masks[1] = '([!start_time] \([!duration]\) [!title]|' + \
336
- '[!start_time]-[!end_time] [!title]|' + \
337
- '[!start_time] [!title])'
338
-
339
- polyrex.parse(list)
340
-
341
- self.import_events polyrex
342
- # for testing only
343
- #polyrex
344
- end
345
-
346
- def save(filename='polyrex.xml')
347
- @polyrex.save filename
348
- end
349
-
350
158
  def this_week()
351
159
 
352
160
  dt = DateTime.now
353
- days = @polyrex.records[dt.month-1].day
161
+ days = @calendar.month(dt.month).day
354
162
 
355
163
  r = days.find {|day| day.date.cweek == dt.cweek }
356
164
  pxweek = PolyrexObjects::Week.new
@@ -365,165 +173,13 @@ class PolyrexCalendar
365
173
  def this_month()
366
174
  self.month(DateTime.now.month)
367
175
  end
368
-
369
- def import_bankholidays(dynarex)
370
- import_dynarex(dynarex, :bankholiday=)
371
- end
372
-
373
- def import_recurring_events(dynarex)
374
-
375
- title = dynarex.summary[:event_title]
376
- cc = ChronicCron.new dynarex.summary[:description].split(/,/,2).first
377
- time_start= "%s:%02d" % cc.to_time.to_a.values_at(2,1)
378
-
379
- dynarex.flat_records.each do |event|
380
-
381
- dt = DateTime.parse(event[:date])
382
- m, d = dt.month, dt.day
383
- record = {title: title, time_start: time_start}
384
-
385
- @polyrex.records[m-1].day[d-1].create.entry record
386
- end
387
- end
388
-
389
- def import_sunrise_times(dynarex)
390
- import_suntimes dynarex, :sunrise=
391
- end
392
-
393
- def import_sunset_times(dynarex)
394
- import_suntimes dynarex, :sunset=
395
- end
396
176
 
397
177
  private
398
178
 
399
- def import_suntimes(dynarex, event_type=:sunrise=)
400
-
401
- dynarex.flat_records.each do |event|
402
-
403
- dt = DateTime.parse(event[:date])
404
- m, d = dt.month, dt.day
405
- @polyrex.records[m-1].day[d-1].method(event_type).call event[:time]
406
- end
407
- end
408
-
409
- def import_dynarex(dynarex, daytype=:event=)
410
-
411
- dynarex.flat_records.each do |event|
412
-
413
- dt = DateTime.parse(event[:date])
414
- m, d = dt.month, dt.day
415
-
416
- case daytype
417
- when :event=
418
- if dynarex.fields.include?(:time) then
419
-
420
- match = event[:time].match(/(\S+)\s*(?:to|-)\s*(\S+)/)
421
-
422
- if match then
423
-
424
- start_time, end_time = match.captures
425
- # add an event entry
426
- title = [event[:title], dynarex.summary[:label],
427
- event[:desc]].compact.join(': ')
428
- record = {
429
- title: title,
430
- time_start: Time.parse(start_time).strftime("%H:%M%p"),
431
- time_end: Time.parse(end_time).strftime("%H:%M%p")
432
- }
433
-
434
- @polyrex.records[m-1].day[d-1].create.entry record
435
- else
436
-
437
- dt = DateTime.parse(event[:date] + ' ' + event[:time])
438
- # add the event
439
- title = [event[:title], dynarex.summary[:label],
440
- event[:desc]].compact.join(': ')
441
- event_label = "%s at %s" % [title, dt.strftime("%H:%M%p")]
442
-
443
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
444
- end
445
-
446
- else
447
-
448
- event_label = "%s at %s" % [event[:title], dt.strftime("%H:%M%p")]
449
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
450
- end
451
-
452
- else
453
-
454
- event_label = "%s" % event[:title]
455
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
456
- end
457
-
458
- end
459
- end
460
-
461
- def import_polyrex(polyrex)
462
-
463
- polyrex.records.each do |day|
464
-
465
- dt = day.date
466
-
467
- sd = dt.strftime("%Y-%b-%d ")
468
- m, i = dt.month, dt.day
469
- cal_day = @polyrex.records[m - 1].day[i-1]
470
-
471
- cal_day.event = day.title
472
-
473
- if day.records.length > 0 then
474
-
475
- raw_entries = day.records
476
-
477
- entries = raw_entries.inject({}) do |r,entry|
478
-
479
- start_time = entry.start_time
480
-
481
- if entry.end_time.length > 0 then
482
-
483
- end_time = entry.end_time
484
- duration = ChronicDuration.output(Time.parse(sd + end_time) \
485
- - Time.parse(sd + start_time))
486
- else
487
-
488
- if entry.duration.length > 0 then
489
- duration = entry.duration
490
- else
491
- duration = '10 mins'
492
- end
493
-
494
- end_time = (Time.parse(sd + start_time) + ChronicDuration.parse(duration))\
495
- .strftime("%H:%M")
496
- end
497
-
498
- r.merge!(start_time => {time_start: start_time, time_end: end_time, \
499
- duration: duration, title: entry.title})
500
-
501
- end
502
-
503
- seconds = entries.keys.map{|x| Time.parse(x) - Time.parse('08:00')}
504
-
505
- unless dt.saturday? or dt.sunday? then
506
- rows = slotted_sort(seconds).map do |x|
507
- (Time.parse('08:00') + x.to_i).strftime("%H:%M") if x
508
- end
509
- else
510
- rows = entries.keys
511
- end
512
-
513
- rows.each do |row|
514
- create = cal_day.create
515
- create.id = @id
516
- create.entry entries[row] || {}
517
- end
518
-
519
- end
520
- end
521
-
522
- end
523
179
 
524
180
  def make_month(m)
525
181
 
526
- cal_month = @polyrex.records[m-1]
182
+ cal_month = @calendar.month(m)
527
183
  days_in_month = cal_month.records
528
184
  pxmonth = cal_month.clone
529
185
  pxmonth.records.each(&:delete)
@@ -578,29 +234,4 @@ class PolyrexCalendar
578
234
  'th' : %w{ th st nd rd th th th th th th }[val % 10]
579
235
  end
580
236
 
581
- def slotted_sort(a)
582
-
583
- upper = 36000 # upper slot value
584
- slot_width = 9000 # 2.5 hours
585
- max_slots = 3
586
-
587
- b = a.reverse.inject([]) do |r,x|
588
-
589
- upper ||= 10; i ||= 0
590
- diff = upper - x
591
-
592
- if diff >= slot_width and (i + a.length) < max_slots then
593
- r << nil
594
- i += 1
595
- upper -= slot_width
596
- redo
597
- else
598
- upper -= slot_width if x <= upper
599
- r << x
600
- end
601
- end
602
-
603
- a = b.+([nil] * max_slots).take(max_slots).reverse
604
- end
605
-
606
237
  end
@@ -2,228 +2,65 @@
2
2
 
3
3
  # file: polyrex-calendar.rb
4
4
 
5
- require 'polyrex'
6
- require 'date'
7
- require 'nokogiri'
8
- require 'chronic_duration'
9
- require 'chronic_cron'
5
+ require 'px-calendarbase'
10
6
 
11
7
 
12
- MONTH = DAY * 30
13
-
14
-
15
- h = {
16
- calendar: 'calendar[year]',
17
- month: 'month[n, title]',
18
- week: 'week[n, mon, no, label]',
19
- day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
20
- entry: 'entry[time_start, time_end, duration, title]'
21
- }
22
- visual_schema = h.values.join '/'
23
- PolyrexObjects.new(visual_schema)
24
-
25
- module LIBRARY
26
-
27
- def fetch_file(filename)
28
-
29
- lib = File.dirname(__FILE__)
30
- File.read File.join(lib, filename )
31
- end
32
-
33
- def generate_webpage(xml, xsl)
34
-
35
- # transform the xml to html
36
- doc = Nokogiri::XML(xml)
37
- xslt = Nokogiri::XSLT(xsl)
38
- xslt.transform(doc).to_s
39
- end
40
- end
41
-
42
- class Polyrex
43
- include LIBRARY
44
-
45
- attr_accessor :xslt, :css_layout, :css_style, :filename
46
-
47
- def inspect()
48
- "#<Polyrex:%s" % __id__
49
- end
50
-
51
- def to_webpage()
52
-
53
- year_xsl = fetch_file self.xslt
54
- year_layout_css = fetch_file self.css_layout
55
- year_css = fetch_file self.css_style
56
- File.open('self.xml','w'){|f| f.write (self.to_xml pretty: true)}
57
- File.open(self.xslt,'w'){|f| f.write year_xsl }
58
- #html = Rexslt.new(month_xsl, self.to_xml).to_xml
59
-
60
- html = generate_webpage self.to_xml, year_xsl
61
- {self.filename => html,
62
- self.css_layout => year_layout_css, self.css_style => year_css}
63
-
64
- end
65
- end
66
-
67
- class PolyrexObjects::Month
68
- include LIBRARY
69
-
70
- attr_accessor :xslt, :css_layout, :css_style
71
-
72
- def inspect()
73
- "#<PolyrexObjects::Month:%s" % __id__
74
- end
75
-
76
- def to_webpage()
77
-
78
- month_xsl = fetch_file self.xslt
79
- month_layout_css = fetch_file self.css_layout
80
- month_css = fetch_file self.css_style
81
-
82
- #html = Rexslt.new(month_xsl, self.to_xml).to_xml
83
-
84
- # add a css selector for the current day
85
- date = Time.now.strftime("%Y-%b-%d")
86
-
87
- e = self.element("records/week/records/day/summary[sdate='#{date}']")
88
- e.attributes[:class] = 'selected' if e
89
-
90
- File.write 'self.xml', self.to_xml(pretty: true)
91
- File.write 'month.xsl', month_xsl
92
-
93
-
94
- html = generate_webpage self.to_xml, month_xsl
95
- {self.title.downcase[0..2] + '_calendar.html' => html,
96
- self.css_layout => month_layout_css, self.css_style => month_css}
97
- end
8
+ class PolyrexObjects
98
9
 
99
- def wk(n)
100
- self.records[n-1]
101
- end
102
- end
103
-
104
- class PolyrexObjects::Week
105
- include LIBRARY
106
-
107
- def inspect()
108
- "#<PolyrexObjects::Week:%s" % __id__
10
+ class Month
11
+
12
+ def wk(n)
13
+ self.records[n-1]
14
+ end
109
15
  end
110
-
111
- def to_webpage()
112
-
113
- week_xsl = fetch_file 'week_calendar.xsl'
114
- week_layout_css = fetch_file 'week_layout.css'
115
- week_css = fetch_file 'week.css'
116
16
 
117
- File.write 'self.xml', self.to_xml(pretty: true)
118
- File.write 'week.xsl', week_xsl
119
- #html = Rexslt.new(week_xsl, self.to_xml).to_xml
120
- #html = xsltproc 'week_calendar.xsl', self.to_xml
17
+ class Week
18
+
19
+ def to_webpage()
121
20
 
122
- # add a css selector for the current day
123
- date = Time.now.strftime("%Y-%b-%d")
21
+ week_xsl = fetch_file 'week_calendar.xsl'
22
+ week_layout_css = fetch_file 'week_layout.css'
23
+ week_css = fetch_file 'week.css'
124
24
 
125
- e = self.element("records/day/summary[sdate='#{date}']")
126
- e.attributes[:class] = 'selected' if e
25
+ File.write 'self.xml', self.to_xml(pretty: true)
26
+ File.write 'week.xsl', week_xsl
27
+ #html = Rexslt.new(week_xsl, self.to_xml).to_xml
28
+ #html = xsltproc 'week_calendar.xsl', self.to_xml
127
29
 
30
+ # add a css selector for the current day
31
+ date = Time.now.strftime("%Y-%b-%d")
128
32
 
129
- html = generate_webpage self.to_xml, week_xsl
130
- {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
131
- 'week.css' => week_css}
132
- end
133
- end
33
+ e = self.element("records/day/summary[sdate='#{date}']")
34
+ e.attributes[:class] = 'selected' if e
134
35
 
135
- class PolyrexObjects::Day
136
36
 
137
- def date()
138
- Date.parse(self.sdate)
37
+ html = generate_webpage self.to_xml, week_xsl
38
+ {'week' + self.no + '_planner.html' => html, 'week_layout.css' => week_layout_css, \
39
+ 'week.css' => week_css}
40
+ end
139
41
  end
140
42
 
141
- def wday()
142
- self.date.wday
143
- end
144
43
 
145
- def day()
146
- self.date.day
147
- end
148
44
  end
149
45
 
150
- class PolyrexCalendar
151
- include LIBRARY
152
-
153
- attr_accessor :xsl, :css, :polyrex, :month_xsl, :month_css
154
- attr_reader :day
46
+ class PolyrexCalendar < PolyrexCalendarBase
155
47
 
156
48
  def initialize(calendar_file=nil, options={})
157
49
 
158
- opts = {year: Time.now.year.to_s}.merge(options)
159
- @year = opts[:year]
160
-
161
- h = {
162
- calendar: 'calendar[year]',
163
- month: 'month[n, title]',
164
- week: 'week[n]',
165
- day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]',
166
- entry: 'entry[time_start, time_end, duration, title]'
167
- }
168
- @schema = %i(calendar month day entry).map{|x| h[x]}.join '/'
169
- @visual_schema = h.values.join '/'
170
-
171
-
172
- if calendar_file then
173
- @polyrex = Polyrex.new calendar_file
174
- @id = @polyrex.id_counter
175
-
176
- else
177
- @id = '1'
178
- # generate the calendar
179
-
180
- a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a
181
-
182
- @polyrex = Polyrex.new(@schema, id_counter: @id)
183
- @polyrex.summary.year = @year
184
-
185
- a.group_by(&:month).each do |month, days|
186
-
187
- @polyrex.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create|
188
- days.each do |x|
189
- create.day sdate: x.strftime("%Y-%b-%d"), xday: x.day.to_s, title: Date::DAYNAMES[x.wday]
190
- end
191
- end
192
- end
193
-
194
- end
195
-
196
- visual_schema = h.values.join '/'
197
- PolyrexObjects.new(visual_schema)
50
+ super(calendar_file, options)
198
51
 
199
52
  @xsl = fetch_file 'calendar.xsl'
200
53
  @css = fetch_file 'layout.css'
201
54
 
202
55
  end
203
56
 
204
- def to_a()
205
- @a
206
- end
207
-
208
- def to_xml()
209
- @polyrex.to_xml pretty: true
210
- end
211
-
212
- def import_events(objx)
213
- @id = @polyrex.id_counter
214
- method('import_'.+(objx.class.to_s.downcase).to_sym).call(objx)
215
- self
216
- end
217
-
218
- alias import! import_events
219
-
220
57
  def inspect()
221
58
  %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">)
222
59
  end
223
60
 
224
61
  def kitchen_planner()
225
62
 
226
- px = @polyrex
63
+ px = @calendar
227
64
 
228
65
  # add a css selector for the current day
229
66
  date = DateTime.now.strftime("%Y-%b-%d")
@@ -252,8 +89,6 @@ class PolyrexCalendar
252
89
  + "summary[sdate='#{date}']")
253
90
  e.attributes[:class] = 'selected' if e
254
91
 
255
-
256
- px.xslt = 'calendar.xsl'
257
92
  px.css_layout = 'layout.css'
258
93
  px.css_style = 'year.css'
259
94
  px.filename = px.summary.year.to_s + '-planner.html'
@@ -285,7 +120,6 @@ class PolyrexCalendar
285
120
 
286
121
  r
287
122
 
288
-
289
123
  end
290
124
 
291
125
  pxmonth.xslt = 'monthday_calendar.xsl'
@@ -320,37 +154,11 @@ class PolyrexCalendar
320
154
  end
321
155
 
322
156
  end
323
- def month_day()
324
- end
325
-
326
- def months
327
- @polyrex.records
328
- end
329
-
330
- def parse_events(list)
331
157
 
332
- polyrex = Polyrex.new('events/dayx[date, title]/entryx[start_time, end_time,' + \
333
- ' duration, title]')
334
-
335
- polyrex.format_masks[1] = '([!start_time] \([!duration]\) [!title]|' + \
336
- '[!start_time]-[!end_time] [!title]|' + \
337
- '[!start_time] [!title])'
338
-
339
- polyrex.parse(list)
340
-
341
- self.import_events polyrex
342
- # for testing only
343
- #polyrex
344
- end
345
-
346
- def save(filename='polyrex.xml')
347
- @polyrex.save filename
348
- end
349
-
350
158
  def this_week()
351
159
 
352
160
  dt = DateTime.now
353
- days = @polyrex.records[dt.month-1].day
161
+ days = @calendar.month(dt.month).day
354
162
 
355
163
  r = days.find {|day| day.date.cweek == dt.cweek }
356
164
  pxweek = PolyrexObjects::Week.new
@@ -365,165 +173,13 @@ class PolyrexCalendar
365
173
  def this_month()
366
174
  self.month(DateTime.now.month)
367
175
  end
368
-
369
- def import_bankholidays(dynarex)
370
- import_dynarex(dynarex, :bankholiday=)
371
- end
372
-
373
- def import_recurring_events(dynarex)
374
-
375
- title = dynarex.summary[:event_title]
376
- cc = ChronicCron.new dynarex.summary[:description].split(/,/,2).first
377
- time_start= "%s:%02d" % cc.to_time.to_a.values_at(2,1)
378
-
379
- dynarex.flat_records.each do |event|
380
-
381
- dt = DateTime.parse(event[:date])
382
- m, d = dt.month, dt.day
383
- record = {title: title, time_start: time_start}
384
-
385
- @polyrex.records[m-1].day[d-1].create.entry record
386
- end
387
- end
388
-
389
- def import_sunrise_times(dynarex)
390
- import_suntimes dynarex, :sunrise=
391
- end
392
-
393
- def import_sunset_times(dynarex)
394
- import_suntimes dynarex, :sunset=
395
- end
396
176
 
397
177
  private
398
178
 
399
- def import_suntimes(dynarex, event_type=:sunrise=)
400
-
401
- dynarex.flat_records.each do |event|
402
-
403
- dt = DateTime.parse(event[:date])
404
- m, d = dt.month, dt.day
405
- @polyrex.records[m-1].day[d-1].method(event_type).call event[:time]
406
- end
407
- end
408
-
409
- def import_dynarex(dynarex, daytype=:event=)
410
-
411
- dynarex.flat_records.each do |event|
412
-
413
- dt = DateTime.parse(event[:date])
414
- m, d = dt.month, dt.day
415
-
416
- case daytype
417
- when :event=
418
- if dynarex.fields.include?(:time) then
419
-
420
- match = event[:time].match(/(\S+)\s*(?:to|-)\s*(\S+)/)
421
-
422
- if match then
423
-
424
- start_time, end_time = match.captures
425
- # add an event entry
426
- title = [event[:title], dynarex.summary[:label],
427
- event[:desc]].compact.join(': ')
428
- record = {
429
- title: title,
430
- time_start: Time.parse(start_time).strftime("%H:%M%p"),
431
- time_end: Time.parse(end_time).strftime("%H:%M%p")
432
- }
433
-
434
- @polyrex.records[m-1].day[d-1].create.entry record
435
- else
436
-
437
- dt = DateTime.parse(event[:date] + ' ' + event[:time])
438
- # add the event
439
- title = [event[:title], dynarex.summary[:label],
440
- event[:desc]].compact.join(': ')
441
- event_label = "%s at %s" % [title, dt.strftime("%H:%M%p")]
442
-
443
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
444
- end
445
-
446
- else
447
-
448
- event_label = "%s at %s" % [event[:title], dt.strftime("%H:%M%p")]
449
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
450
- end
451
-
452
- else
453
-
454
- event_label = "%s" % event[:title]
455
- @polyrex.records[m-1].day[d-1].method(daytype).call event_label
456
- end
457
-
458
- end
459
- end
460
-
461
- def import_polyrex(polyrex)
462
-
463
- polyrex.records.each do |day|
464
-
465
- dt = day.date
466
-
467
- sd = dt.strftime("%Y-%b-%d ")
468
- m, i = dt.month, dt.day
469
- cal_day = @polyrex.records[m - 1].day[i-1]
470
-
471
- cal_day.event = day.title
472
-
473
- if day.records.length > 0 then
474
-
475
- raw_entries = day.records
476
-
477
- entries = raw_entries.inject({}) do |r,entry|
478
-
479
- start_time = entry.start_time
480
-
481
- if entry.end_time.length > 0 then
482
-
483
- end_time = entry.end_time
484
- duration = ChronicDuration.output(Time.parse(sd + end_time) \
485
- - Time.parse(sd + start_time))
486
- else
487
-
488
- if entry.duration.length > 0 then
489
- duration = entry.duration
490
- else
491
- duration = '10 mins'
492
- end
493
-
494
- end_time = (Time.parse(sd + start_time) + ChronicDuration.parse(duration))\
495
- .strftime("%H:%M")
496
- end
497
-
498
- r.merge!(start_time => {time_start: start_time, time_end: end_time, \
499
- duration: duration, title: entry.title})
500
-
501
- end
502
-
503
- seconds = entries.keys.map{|x| Time.parse(x) - Time.parse('08:00')}
504
-
505
- unless dt.saturday? or dt.sunday? then
506
- rows = slotted_sort(seconds).map do |x|
507
- (Time.parse('08:00') + x.to_i).strftime("%H:%M") if x
508
- end
509
- else
510
- rows = entries.keys
511
- end
512
-
513
- rows.each do |row|
514
- create = cal_day.create
515
- create.id = @id
516
- create.entry entries[row] || {}
517
- end
518
-
519
- end
520
- end
521
-
522
- end
523
179
 
524
180
  def make_month(m)
525
181
 
526
- cal_month = @polyrex.records[m-1]
182
+ cal_month = @calendar.month(m)
527
183
  days_in_month = cal_month.records
528
184
  pxmonth = cal_month.clone
529
185
  pxmonth.records.each(&:delete)
@@ -578,30 +234,4 @@ class PolyrexCalendar
578
234
  'th' : %w{ th st nd rd th th th th th th }[val % 10]
579
235
  end
580
236
 
581
- def slotted_sort(a)
582
-
583
- upper = 36000 # upper slot value
584
- slot_width = 9000 # 2.5 hours
585
- max_slots = 3
586
-
587
- b = a.reverse.inject([]) do |r,x|
588
-
589
- upper ||= 10; i ||= 0
590
- diff = upper - x
591
-
592
- if diff >= slot_width and (i + a.length) < max_slots then
593
- r << nil
594
- i += 1
595
- upper -= slot_width
596
- redo
597
- else
598
- upper -= slot_width if x <= upper
599
- r << x
600
- end
601
- end
602
-
603
- a = b.+([nil] * max_slots).take(max_slots).reverse
604
- end
605
-
606
-
607
237
  end
data.tar.gz.sig CHANGED
Binary file
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.3.11
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,90 +31,10 @@ cert_chain:
31
31
  V2LbfuIuDVCUDR9ON1ozFySFLuTnZSmO6lR4UsFjHKwbtnnbapfQVvEJ1PLW/F13
32
32
  1r3+lzIVNJhpdQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-07-06 00:00:00.000000000 Z
34
+ date: 2014-10-02 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
- name: polyrex
38
- requirement: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '0.9'
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.9.3
46
- type: :runtime
47
- prerelease: false
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '0.9'
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 0.9.3
56
- - !ruby/object:Gem::Dependency
57
- name: nokogiri
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '1.6'
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: 1.6.2.1
66
- type: :runtime
67
- prerelease: false
68
- version_requirements: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - "~>"
71
- - !ruby/object:Gem::Version
72
- version: '1.6'
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.6.2.1
76
- - !ruby/object:Gem::Dependency
77
- name: chronic_duration
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.4
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.4
96
- - !ruby/object:Gem::Dependency
97
- name: chronic_cron
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '0.2'
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: 0.2.33
106
- type: :runtime
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '0.2'
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: 0.2.33
116
- - !ruby/object:Gem::Dependency
117
- name: rxfhelper
37
+ name: polyrex_calendarbase
118
38
  requirement: !ruby/object:Gem::Requirement
119
39
  requirements:
120
40
  - - "~>"
@@ -122,7 +42,7 @@ dependencies:
122
42
  version: '0.1'
123
43
  - - ">="
124
44
  - !ruby/object:Gem::Version
125
- version: 0.1.12
45
+ version: 0.1.3
126
46
  type: :runtime
127
47
  prerelease: false
128
48
  version_requirements: !ruby/object:Gem::Requirement
@@ -132,7 +52,7 @@ dependencies:
132
52
  version: '0.1'
133
53
  - - ">="
134
54
  - !ruby/object:Gem::Version
135
- version: 0.1.12
55
+ version: 0.1.3
136
56
  description:
137
57
  email: james@r0bertson.co.uk
138
58
  executables: []
@@ -180,4 +100,3 @@ signing_key:
180
100
  specification_version: 4
181
101
  summary: Generates an HTML calendar from a Polyrex document
182
102
  test_files: []
183
- has_rdoc:
metadata.gz.sig CHANGED
Binary file