Class: Mo2tex::Calendar

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

Defined Under Namespace

Classes: UnknownEvent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Calendar

Returns a new instance of Calendar.



15
16
17
18
19
20
21
# File 'lib/mo2tex/calendar.rb', line 15

def initialize(config)
    @filename = config['file']
    @start_date = DateTime.parse(config['start_date'].to_s)
    @end_date = DateTime.parse(config['end_date'].to_s)
    @exclude = ExclusionManager.new(config['exclude'], self.start_date, self.end_date)
    @day_schedule_templates = parse_day_schedule_templates(config['day_schedule'])
end

Instance Attribute Details

#day_schedule_templatesObject (readonly)

Returns the value of attribute day_schedule_templates.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def day_schedule_templates
  @day_schedule_templates
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def end_date
  @end_date
end

#eventsObject (readonly)

Returns the value of attribute events.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def events
  @events
end

#excludeObject (readonly)

Returns the value of attribute exclude.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def exclude
  @exclude
end

#filenameObject (readonly)

Returns the value of attribute filename.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def filename
  @filename
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



11
12
13
# File 'lib/mo2tex/calendar.rb', line 11

def start_date
  @start_date
end

Instance Method Details

#create_icalendar(school) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mo2tex/calendar.rb', line 23

def create_icalendar(school)
  ical = Icalendar::Calendar.new
  school.courses.each do
    |title, course|
    course.events.each do
      |ev|
      ev.to_ical(ical)
    end
  end
  return ical.publish
end

#create_pic_schedule(school) ⇒ Object



35
36
37
# File 'lib/mo2tex/calendar.rb', line 35

def create_pic_schedule(school)
  pic = Pic.new(school) 
end

#to_file(school, fname = nil) ⇒ Object



39
40
41
42
43
44
# File 'lib/mo2tex/calendar.rb', line 39

def to_file(school, fname = nil)
  fname ||= self.filename
  ical = self.create_icalendar(school)
  File.open(fname, 'w') { |fh| fh.puts(ical.to_ical) }
  return fname
end