Class: Calagator::Event::IcalRenderer
- Inherits:
-
Object
- Object
- Calagator::Event::IcalRenderer
- Defined in:
- app/models/calagator/event/ical_renderer.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#imported_from ⇒ Object
readonly
Returns the value of attribute imported_from.
Class Method Summary collapse
- .add_name(output) ⇒ Object
- .normalize_line_endings(output) ⇒ Object
- .render(events, opts = {}) ⇒ Object
- .render_icalendar(events, opts) ⇒ Object
Instance Method Summary collapse
- #add_event_to(entry) ⇒ Object
-
#initialize(event, opts) ⇒ IcalRenderer
constructor
A new instance of IcalRenderer.
Constructor Details
#initialize(event, opts) ⇒ IcalRenderer
Returns a new instance of IcalRenderer.
49 50 51 52 |
# File 'app/models/calagator/event/ical_renderer.rb', line 49 def initialize(event, opts) @event = event @imported_from = opts[:url_helper].call(event).to_s if opts[:url_helper] end |
Instance Attribute Details
#event ⇒ Object (readonly)
Returns the value of attribute event.
47 48 49 |
# File 'app/models/calagator/event/ical_renderer.rb', line 47 def event @event end |
#imported_from ⇒ Object (readonly)
Returns the value of attribute imported_from.
47 48 49 |
# File 'app/models/calagator/event/ical_renderer.rb', line 47 def imported_from @imported_from end |
Class Method Details
.add_name(output) ⇒ Object
39 40 41 |
# File 'app/models/calagator/event/ical_renderer.rb', line 39 def self.add_name(output) output.sub(/(CALSCALE:\w+)/i, "\\1\nX-WR-CALNAME:#{Calagator.title}\nMETHOD:PUBLISH") end |
.normalize_line_endings(output) ⇒ Object
43 44 45 |
# File 'app/models/calagator/event/ical_renderer.rb', line 43 def self.normalize_line_endings(output) output.gsub(/\r?\n/, "\r\n") end |
.render(events, opts = {}) ⇒ Object
20 21 22 23 24 |
# File 'app/models/calagator/event/ical_renderer.rb', line 20 def self.render(events, opts = {}) output = render_icalendar(events, opts) output = add_name(output) normalize_line_endings(output) end |
.render_icalendar(events, opts) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/calagator/event/ical_renderer.rb', line 26 def self.render_icalendar(events, opts) cal = RiCal.Calendar do |calendar| calendar.prodid = "-//Calagator//EN" Array(events).each do |event| calendar.event do |entry| new(event, opts).add_event_to(entry) end end end cal.export end |
Instance Method Details
#add_event_to(entry) ⇒ Object
54 55 56 57 58 59 |
# File 'app/models/calagator/event/ical_renderer.rb', line 54 def add_event_to(entry) fields.each do |field| value = send(field) # value = summary entry.send field, value if value # entry.summary summary if summary end end |