Class: Icalendar2::Calendar
- Inherits:
-
Object
- Object
- Icalendar2::Calendar
- Defined in:
- lib/icalendar2/calendar.rb
Overview
Constant Summary collapse
- VALUE =
"VCALENDAR"
Instance Method Summary collapse
- #add_component(component) ⇒ Object
- #add_event(event) ⇒ Object
- #calscale(value = nil) ⇒ Object
- #event(&block) ⇒ Object
- #events ⇒ Object
-
#initialize ⇒ Calendar
constructor
A new instance of Calendar.
- #method_property(value = nil) ⇒ Object
- #prodid(value = nil) ⇒ Object
- #set_property(property_name, value, parameters = {}) ⇒ Object
- #to_ical ⇒ Object
- #valid? ⇒ Boolean
- #version(value = nil) ⇒ Object
Constructor Details
#initialize ⇒ Calendar
Returns a new instance of Calendar.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/icalendar2/calendar.rb', line 6 def initialize @components = { Event::VALUE => [] } @properties = { "calscale" => Property::Nil.new, "method" => Property::Nil.new, "prodid" => Property::Nil.new, "version" => Property::Nil.new } end |
Instance Method Details
#add_component(component) ⇒ Object
72 73 74 |
# File 'lib/icalendar2/calendar.rb', line 72 def add_component(component) @components[component.class::VALUE] << component end |
#add_event(event) ⇒ Object
59 60 61 |
# File 'lib/icalendar2/calendar.rb', line 59 def add_event(event) events << event end |
#calscale(value = nil) ⇒ Object
18 19 20 |
# File 'lib/icalendar2/calendar.rb', line 18 def calscale(value = nil) set_property(:calscale, value) end |
#event(&block) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/icalendar2/calendar.rb', line 51 def event(&block) e = Event.new e.instance_eval(&block) events << e e end |
#events ⇒ Object
47 48 49 |
# File 'lib/icalendar2/calendar.rb', line 47 def events @components[Event::VALUE] end |
#method_property(value = nil) ⇒ Object
22 23 24 |
# File 'lib/icalendar2/calendar.rb', line 22 def method_property(value = nil) set_property(:method, value) end |
#prodid(value = nil) ⇒ Object
26 27 28 |
# File 'lib/icalendar2/calendar.rb', line 26 def prodid(value = nil) set_property(:prodid, value) end |
#set_property(property_name, value, parameters = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/icalendar2/calendar.rb', line 34 def set_property(property_name, value, parameters = {}) property = property_name.to_s.downcase if value.nil? @properties[property].value.to_s elsif (factory = CalendarProperty.get_factory(property_name)) if value.is_a? factory @properties[property] = value else @properties[property] = factory.new(value) end end end |
#to_ical ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/icalendar2/calendar.rb', line 63 def to_ical str = "#{Tokens::COMPONENT_BEGIN}:#{VALUE}#{Tokens::CRLF}" str << body_to_ical str << "#{Tokens::COMPONENT_END}:#{VALUE}#{Tokens::CRLF}" str = str.encode("UTF-8") if str.respond_to?(:encode) str end |
#valid? ⇒ Boolean
76 77 78 |
# File 'lib/icalendar2/calendar.rb', line 76 def valid? events.all?(&:valid?) end |
#version(value = nil) ⇒ Object
30 31 32 |
# File 'lib/icalendar2/calendar.rb', line 30 def version(value = nil) set_property(:version, value) end |