Class: PolyrexCalendarBase
- Inherits:
-
Object
- Object
- PolyrexCalendarBase
- Includes:
- LIBRARY2
- 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.
182 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 |
# File 'lib/polyrex_calendarbase.rb', line 182 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.
179 180 181 |
# File 'lib/polyrex_calendarbase.rb', line 179 def calendar @calendar end |
#css ⇒ Object
Returns the value of attribute css.
179 180 181 |
# File 'lib/polyrex_calendarbase.rb', line 179 def css @css end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
180 181 182 |
# File 'lib/polyrex_calendarbase.rb', line 180 def day @day end |
#month_css ⇒ Object
Returns the value of attribute month_css.
179 180 181 |
# File 'lib/polyrex_calendarbase.rb', line 179 def month_css @month_css end |
#month_xsl ⇒ Object
Returns the value of attribute month_xsl.
179 180 181 |
# File 'lib/polyrex_calendarbase.rb', line 179 def month_xsl @month_xsl end |
#xsl ⇒ Object
Returns the value of attribute xsl.
179 180 181 |
# File 'lib/polyrex_calendarbase.rb', line 179 def xsl @xsl end |
Instance Method Details
#find(s) ⇒ Object
229 230 231 232 |
# File 'lib/polyrex_calendarbase.rb', line 229 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
298 299 300 |
# File 'lib/polyrex_calendarbase.rb', line 298 def import_bankholidays(dynarex) import_dynarex(dynarex, :bankholiday=) end |
#import_events(objx) ⇒ Object Also known as: import!
238 239 240 241 242 |
# File 'lib/polyrex_calendarbase.rb', line 238 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
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/polyrex_calendarbase.rb', line 302 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
318 319 320 |
# File 'lib/polyrex_calendarbase.rb', line 318 def import_sunrise_times(dynarex) import_suntimes dynarex, :sunrise= end |
#import_sunset_times(dynarex) ⇒ Object
322 323 324 |
# File 'lib/polyrex_calendarbase.rb', line 322 def import_sunset_times(dynarex) import_suntimes dynarex, :sunset= end |
#inspect ⇒ Object
246 247 248 |
# File 'lib/polyrex_calendarbase.rb', line 246 def inspect() %Q(=> #<PolyrexCalendarBase:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#month(n) ⇒ Object
250 251 252 |
# File 'lib/polyrex_calendarbase.rb', line 250 def month(n) @calendar.month(n) end |
#months ⇒ Object
254 255 256 |
# File 'lib/polyrex_calendarbase.rb', line 254 def months @calendar.records end |
#parse_events(list) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/polyrex_calendarbase.rb', line 258 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
274 275 276 277 |
# File 'lib/polyrex_calendarbase.rb', line 274 def save(filename=@calendar_file) @calendar_file = 'calendar.xml' unless filename @calendar.save filename, pretty: true end |
#this_month ⇒ Object
294 295 296 |
# File 'lib/polyrex_calendarbase.rb', line 294 def this_month() @calendar.month(DateTime.now.month) end |
#this_week ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/polyrex_calendarbase.rb', line 279 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
234 235 236 |
# File 'lib/polyrex_calendarbase.rb', line 234 def to_xml() @calendar.to_xml pretty: true end |