class VacationRentalsIcalAdapters::IcalConverter

Attributes

events[R]

Public Class Methods

to_ical(events) click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 2
def self.to_ical(events)
  new(events).to_ical
end

Private Class Methods

new(events) click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 9
def initialize(events)
  @events = events
end

Public Instance Methods

to_ical() click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 14
def to_ical
  [
    ical_beginning,
    events.map { |event| ical_event_from(event) },
    ical_ending,
  ].reject(&:empty?).join("\n")
end

Private Instance Methods

format_date(date) click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 36
def format_date(date)
  date.strftime("%Y%m%d")
end
ical_beginning() click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 24
  def ical_beginning
    %Q{BEGIN:VCALENDAR
VERSION:2.0}
  end
ical_ending() click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 40
def ical_ending
  %Q{END:VCALENDAR}
end
ical_event_from(event) click to toggle source
# File lib/vacation_rentals_ical_adapters/ical_converter.rb, line 29
  def ical_event_from(event)
%Q{BEGIN:VEVENT
DTEND;VALUE=DATE:#{format_date(event.end_date)}
DTSTART;VALUE=DATE:#{format_date(event.start_date)}
END:VEVENT}
  end