Class: ICALParser

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ICALParser) initialize(cals)

Returns a new instance of ICALParser



10
11
12
# File 'lib/ical_parser.rb', line 10

def initialize(cals)
  @cals = cals
end

Class Method Details

+ (Object) parse(data)



6
7
8
# File 'lib/ical_parser.rb', line 6

def self.parse(data)
  new Icalendar.parse(data)
end

Instance Method Details

- (Object) current_events



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ical_parser.rb', line 15

def current_events
  events = []

  @cals.each do |cal|
    cal.events.each do |event|
      range = (event.dtstart.to_time.to_i..event.dtend.to_time.to_i)
      if range.cover?(Time.now.to_i)
        events.push({
          "message" => event.summary
        })
      end
    end
  end

  return events

end