Class: Calagator::Source::Parser::Hcal

Inherits:
Calagator::Source::Parser show all
Defined in:
app/models/calagator/source/parser/hcal.rb

Constant Summary collapse

EVENT_TO_HCALENDAR_FIELD_MAP =
{
  title: :name,
  description: :description,
  start_time: :start,
  end_time: :end,
  url: :url,
  venue: :location
}.freeze

Instance Attribute Summary

Attributes inherited from Calagator::Source::Parser

#source, #url

Instance Method Summary collapse

Methods inherited from Calagator::Source::Parser

<=>, inherited, labels, read_url, to_events

Instance Method Details

#to_eventsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/calagator/source/parser/hcal.rb', line 22

def to_events
  hcals.map do |hcal|
    event = Event.new
    event.source = source
    EVENT_TO_HCALENDAR_FIELD_MAP.each do |field, hcal_field|
      next unless hcal.respond_to?(hcal_field)
      next unless value = decoded_field(hcal, hcal_field)

      event.send "#{field}=", value
    end
    event_or_duplicate(event)
  end.uniq do |event|
    [event.attributes, event.venue.try(:attributes)]
  end
end