Class: PolyrexCalendarBase
- Inherits:
-
Object
- Object
- PolyrexCalendarBase
- Includes:
- LIBRARY2, RXFHelperModule
- Defined in:
- lib/polyrex_calendarbase.rb
Instance Attribute Summary collapse
-
#calendar ⇒ Object
Returns the value of attribute calendar.
-
#css ⇒ Object
Returns the value of attribute css.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#month_css ⇒ Object
Returns the value of attribute month_css.
-
#month_xsl ⇒ Object
Returns the value of attribute month_xsl.
-
#xsl ⇒ Object
Returns the value of attribute xsl.
Instance Method Summary collapse
- #find(s) ⇒ Object
- #import_bankholidays(dynarex) ⇒ Object
- #import_events(objx) ⇒ Object (also: #import!)
- #import_recurring_events(dynarex) ⇒ Object
- #import_sunrise_times(dynarex) ⇒ Object
- #import_sunset_times(dynarex) ⇒ Object
-
#initialize(calendar_file = nil, year: Date.today.year.to_s) ⇒ PolyrexCalendarBase
constructor
A new instance of PolyrexCalendarBase.
- #inspect ⇒ Object
- #month(n) ⇒ Object
- #months ⇒ Object
- #parse_events(list) ⇒ Object
- #save(filename = @calendar_file) ⇒ Object
- #this_month ⇒ Object
- #this_week ⇒ Object
- #to_xml ⇒ Object
Methods included from LIBRARY2
#fetch_file, #fetch_filepath, #generate_webpage, #read
Constructor Details
#initialize(calendar_file = nil, year: Date.today.year.to_s) ⇒ PolyrexCalendarBase
Returns a new instance of PolyrexCalendarBase.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/polyrex_calendarbase.rb', line 183 def initialize(calendar_file=nil, year: Date.today.year.to_s) @calendar_file = calendar_file @year = year.to_s h = { calendar: 'calendar[year]', month: 'month[n, title]', week: 'week[n]', day: 'day[sdate, xday, event, bankholiday, title, sunrise, sunset]', entry: 'entry[time_start, time_end, duration, title]' } @schema = %i(calendar month day entry).map{|x| h[x]}.join '/' @visual_schema = h.values.join '/' if calendar_file then @calendar = Calendar.new calendar_file @id = @calendar.id_counter else @id = '1' # generate the calendar a = (Date.parse(@year + '-01-01')...Date.parse(@year.succ + '-01-01')).to_a @calendar = Calendar.new(@schema, id_counter: @id) @calendar.summary.year = @year a.group_by(&:month).each do |month, days| @calendar.create.month no: month.to_s, title: Date::MONTHNAMES[month] do |create| days.each do |x| create.day sdate: x.strftime("%Y-%b-%d"), xday: x.day.to_s, title: Date::DAYNAMES[x.wday] end end end end visual_schema = h.values.join '/' CalendarObjects.new(visual_schema) end |
Instance Attribute Details
#calendar ⇒ Object
Returns the value of attribute calendar.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def calendar @calendar end |
#css ⇒ Object
Returns the value of attribute css.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def css @css end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
181 182 183 |
# File 'lib/polyrex_calendarbase.rb', line 181 def day @day end |
#month_css ⇒ Object
Returns the value of attribute month_css.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def month_css @month_css end |
#month_xsl ⇒ Object
Returns the value of attribute month_xsl.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def month_xsl @month_xsl end |
#xsl ⇒ Object
Returns the value of attribute xsl.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def xsl @xsl end |
Instance Method Details
#find(s) ⇒ Object
230 231 232 233 |
# File 'lib/polyrex_calendarbase.rb', line 230 def find(s) dt = Chronic.parse s, now: Time.local(@year,1,1) @calendar.month(dt.month).d(dt.day) end |
#import_bankholidays(dynarex) ⇒ Object
299 300 301 |
# File 'lib/polyrex_calendarbase.rb', line 299 def import_bankholidays(dynarex) import_dynarex(dynarex, :bankholiday=) end |
#import_events(objx) ⇒ Object Also known as: import!
239 240 241 242 243 |
# File 'lib/polyrex_calendarbase.rb', line 239 def import_events(objx) @id = @calendar.id_counter method('import_'.+(objx.class.to_s.downcase).to_sym).call(objx) self end |
#import_recurring_events(dynarex) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/polyrex_calendarbase.rb', line 303 def import_recurring_events(dynarex) title = dynarex.summary[:event_title] cc = ChronicCron.new dynarex.summary[:description].split(/,/,2).first time_start= "%s:%02d" % cc.to_time.to_a.values_at(2,1) dynarex.flat_records.each do |event| dt = DateTime.parse(event[:date]) m, d = dt.month, dt.day record = {title: title, time_start: time_start} @calendar.month(m).d(d).create.entry record end end |
#import_sunrise_times(dynarex) ⇒ Object
319 320 321 |
# File 'lib/polyrex_calendarbase.rb', line 319 def import_sunrise_times(dynarex) import_suntimes dynarex, :sunrise= end |
#import_sunset_times(dynarex) ⇒ Object
323 324 325 |
# File 'lib/polyrex_calendarbase.rb', line 323 def import_sunset_times(dynarex) import_suntimes dynarex, :sunset= end |
#inspect ⇒ Object
247 248 249 |
# File 'lib/polyrex_calendarbase.rb', line 247 def inspect() %Q(=> #<PolyrexCalendarBase:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#month(n) ⇒ Object
251 252 253 |
# File 'lib/polyrex_calendarbase.rb', line 251 def month(n) @calendar.month(n) end |
#months ⇒ Object
255 256 257 |
# File 'lib/polyrex_calendarbase.rb', line 255 def months @calendar.records end |
#parse_events(list) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/polyrex_calendarbase.rb', line 259 def parse_events(list) polyrex = Polyrex.new('events/dayx[date, title]/entryx[start_time, end_time,' + \ ' duration, title]') polyrex.format_masks[1] = '([!start_time] \([!duration]\) [!title]|' + \ '[!start_time]-[!end_time] [!title]|' + \ '[!start_time] [!title])' polyrex.parse(list) self.import_events polyrex # for testing only #polyrex end |
#save(filename = @calendar_file) ⇒ Object
275 276 277 278 |
# File 'lib/polyrex_calendarbase.rb', line 275 def save(filename=@calendar_file) @calendar_file = 'calendar.xml' unless filename @calendar.save filename, pretty: true end |
#this_month ⇒ Object
295 296 297 |
# File 'lib/polyrex_calendarbase.rb', line 295 def this_month() @calendar.month(DateTime.now.month) end |
#this_week ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/polyrex_calendarbase.rb', line 280 def this_week() dt = DateTime.now days = @calendar.month(dt.month).day r = days.find {|day| day.date.cweek == dt.cweek } pxweek = PolyrexObjects::Week.new pxweek.mon = Date::MONTHNAMES[dt.month] pxweek.no = dt.cweek.to_s pxweek.label = '' days[days.index(r),7].each{|day| pxweek.add day } pxweek end |
#to_xml ⇒ Object
235 236 237 |
# File 'lib/polyrex_calendarbase.rb', line 235 def to_xml() @calendar.to_xml pretty: true end |