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.
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 229 230 231 232 233 234 |
# File 'lib/polyrex_calendarbase.rb', line 189 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.
186 187 188 |
# File 'lib/polyrex_calendarbase.rb', line 186 def calendar @calendar end |
#css ⇒ Object
Returns the value of attribute css.
186 187 188 |
# File 'lib/polyrex_calendarbase.rb', line 186 def css @css end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
187 188 189 |
# File 'lib/polyrex_calendarbase.rb', line 187 def day @day end |
#month_css ⇒ Object
Returns the value of attribute month_css.
186 187 188 |
# File 'lib/polyrex_calendarbase.rb', line 186 def month_css @month_css end |
#month_xsl ⇒ Object
Returns the value of attribute month_xsl.
186 187 188 |
# File 'lib/polyrex_calendarbase.rb', line 186 def month_xsl @month_xsl end |
#xsl ⇒ Object
Returns the value of attribute xsl.
186 187 188 |
# File 'lib/polyrex_calendarbase.rb', line 186 def xsl @xsl end |
Instance Method Details
#find(s) ⇒ Object
236 237 238 239 |
# File 'lib/polyrex_calendarbase.rb', line 236 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
305 306 307 |
# File 'lib/polyrex_calendarbase.rb', line 305 def import_bankholidays(dynarex) import_dynarex(dynarex, :bankholiday=) end |
#import_events(objx) ⇒ Object Also known as: import!
245 246 247 248 249 |
# File 'lib/polyrex_calendarbase.rb', line 245 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
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/polyrex_calendarbase.rb', line 309 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
325 326 327 |
# File 'lib/polyrex_calendarbase.rb', line 325 def import_sunrise_times(dynarex) import_suntimes dynarex, :sunrise= end |
#import_sunset_times(dynarex) ⇒ Object
329 330 331 |
# File 'lib/polyrex_calendarbase.rb', line 329 def import_sunset_times(dynarex) import_suntimes dynarex, :sunset= end |
#inspect ⇒ Object
253 254 255 |
# File 'lib/polyrex_calendarbase.rb', line 253 def inspect() %Q(=> #<PolyrexCalendarBase:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#month(n) ⇒ Object
257 258 259 |
# File 'lib/polyrex_calendarbase.rb', line 257 def month(n) @calendar.month(n) end |
#months ⇒ Object
261 262 263 |
# File 'lib/polyrex_calendarbase.rb', line 261 def months @calendar.records end |
#parse_events(list) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/polyrex_calendarbase.rb', line 265 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
281 282 283 284 |
# File 'lib/polyrex_calendarbase.rb', line 281 def save(filename=@calendar_file) @calendar_file = 'calendar.xml' unless filename @calendar.save filename, pretty: true end |
#this_month ⇒ Object
301 302 303 |
# File 'lib/polyrex_calendarbase.rb', line 301 def this_month() @calendar.month(DateTime.now.month) end |
#this_week ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/polyrex_calendarbase.rb', line 286 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
241 242 243 |
# File 'lib/polyrex_calendarbase.rb', line 241 def to_xml() @calendar.to_xml pretty: true end |