Class: Icalendar::Values::DateOrDateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/icalendar/values/date_or_date_time.rb

Overview

DateOrDateTime can be used to set an attribute to either a Date or a DateTime value. It should not be used wihtout also invoking the ‘call` method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, params = {}) ⇒ DateOrDateTime

Returns a new instance of DateOrDateTime.



9
10
11
12
# File 'lib/icalendar/values/date_or_date_time.rb', line 9

def initialize(value, params = {})
  @value = value
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/icalendar/values/date_or_date_time.rb', line 8

def params
  @params
end

#parsedObject (readonly)

Returns the value of attribute parsed.



8
9
10
# File 'lib/icalendar/values/date_or_date_time.rb', line 8

def parsed
  @parsed
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/icalendar/values/date_or_date_time.rb', line 8

def value
  @value
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
# File 'lib/icalendar/values/date_or_date_time.rb', line 14

def call
  @parsed ||= begin
                Icalendar::Values::DateTime.new value, params
              rescue Icalendar::Values::DateTime::FormatError
                Icalendar::Values::Date.new value, params
              end
end

#to_icalObject



22
23
24
# File 'lib/icalendar/values/date_or_date_time.rb', line 22

def to_ical
  fail NoMethodError, 'You cannot use DateOrDateTime directly. Invoke `call` before `to_ical`'
end