Class: Icalendar::Values::Date
- Inherits:
-
Icalendar::Value
- Object
- SimpleDelegator
- Icalendar::Value
- Icalendar::Values::Date
- Defined in:
- lib/icalendar/values/date.rb
Defined Under Namespace
Classes: FormatError
Constant Summary collapse
- FORMAT =
'%Y%m%d'
Instance Attribute Summary
Attributes inherited from Icalendar::Value
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(value, params = {}) ⇒ Date
constructor
A new instance of Date.
- #value_ical ⇒ Object
Methods inherited from Icalendar::Value
#ical_param, #params_ical, #to_ical, #value, value_type, #value_type
Constructor Details
#initialize(value, params = {}) ⇒ Date
Returns a new instance of Date.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/icalendar/values/date.rb', line 9 def initialize(value, params = {}) params.delete 'tzid' params.delete 'x-tz-info' if value.is_a? String begin parsed_date = ::Date.strptime(value, FORMAT) rescue ArgumentError => e raise FormatError.new("Failed to parse \"#{value}\" - #{e.}") end super parsed_date, params elsif value.respond_to? :to_date super value.to_date, params else super end end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/icalendar/values/date.rb', line 31 def <=>(other) if other.is_a?(Icalendar::Values::Date) || other.is_a?(Icalendar::Values::DateTime) value_ical <=> other.value_ical else nil end end |
#value_ical ⇒ Object
27 28 29 |
# File 'lib/icalendar/values/date.rb', line 27 def value_ical value.strftime FORMAT end |