Class: EventDb::EventCalendar

Inherits:
Object
  • Object
show all
Defined in:
lib/eventdb/calendar.rb

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ EventCalendar

Returns a new instance of EventCalendar.



52
53
54
55
# File 'lib/eventdb/calendar.rb', line 52

def initialize( events )
  @events = events.sort { |l,r| r.start_date <=> l.start_date }   ## sort events by date (newest first)
  @tmpl = File.read_utf8( "#{EventDb.root}/templates/CALENDAR.md.erb" )
end

Instance Method Details

#eventsObject



57
58
59
60
# File 'lib/eventdb/calendar.rb', line 57

def events
  ## note: return new cursor  -- use decorator (instead of extra loop arg, why? why not?
  EventCursor.new( @events )
end

#renderObject



62
63
64
# File 'lib/eventdb/calendar.rb', line 62

def render
  ERB.new( @tmpl, nil, '<>' ).result( binding )   # <> omit newline for lines starting with <% and ending in %>
end

#save(path = './CALENDAR.md') ⇒ Object

use (rename to) save_as - why? why not??



66
67
68
69
70
# File 'lib/eventdb/calendar.rb', line 66

def save( path = './CALENDAR.md' )   ## use (rename to) save_as - why? why not?? 
  File.open( path, 'w' ) do |f|
    f.write( render )
  end
end