Class: Icalendar::Values::Date

Inherits:
Icalendar::Value show all
Defined in:
lib/icalendar/values/date.rb

Constant Summary collapse

FORMAT =
'%Y%m%d'

Instance Attribute Summary

Attributes inherited from Icalendar::Value

#ical_params

Instance Method Summary collapse

Methods inherited from Icalendar::Value

#ical_param, #params_ical, #to_ical, #value, value_type

Constructor Details

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

Returns a new instance of Date.



9
10
11
12
13
14
15
16
17
# File 'lib/icalendar/values/date.rb', line 9

def initialize(value, params = {})
  if value.is_a? String
    super ::Date.strptime(value, FORMAT), params
  elsif value.respond_to? :to_date
    super value.to_date, params
  else
    super
  end
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/icalendar/values/date.rb', line 23

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_icalObject



19
20
21
# File 'lib/icalendar/values/date.rb', line 19

def value_ical
  value.strftime FORMAT
end