Class: RiCal::PropertyValue::Date
- Inherits:
-
RiCal::PropertyValue
- Object
- RiCal::PropertyValue
- RiCal::PropertyValue::Date
- Defined in:
- lib/ri_cal/property_value/date.rb
Overview
-
©2009 Rick DeNatale
-
All rights reserved. Refer to the file README.txt for the license
RiCal::PropertyValue::CalAddress represents an icalendar Date property value which is defined in RFC 2445 section 4.3.4 p 34
Instance Attribute Summary
Attributes inherited from RiCal::PropertyValue
Instance Method Summary collapse
-
#add_date_times_to(required_timezones) ⇒ Object
:nodoc:.
-
#advance(options) ⇒ Object
:nodoc:.
-
#change(options) ⇒ Object
:nodoc:.
-
#compute_advance(d, options) ⇒ Object
:nodoc:.
-
#compute_change(d, options) ⇒ Object
:nodoc:.
-
#day ⇒ Object
Returns the day of the month.
-
#method_missing(selector, *args) ⇒ Object
Delegate unknown messages to the wrappered Date instance.
-
#month ⇒ Object
Returns the month of the year (1..12).
-
#occurrence_hash(default_duration) ⇒ Object
TODO: consider if this should be a period rather than a hash.
-
#ruby_value ⇒ Object
(also: #to_ri_cal_ruby_value)
Returns the ruby representation a ::Date.
-
#to_ri_cal_date_or_date_time_value ⇒ Object
Return the “Natural’ property value for the date_property, in this case the date property itself.”.
-
#to_ri_cal_date_time_value ⇒ Object
Return an instance of RiCal::PropertyValue::DateTime representing the start of this date.
-
#to_ri_cal_date_value ⇒ Object
Return this date property.
-
#value ⇒ Object
Returns the value of the reciever as an RFC 2445 iCalendar string.
-
#value=(val) ⇒ Object
Set the value of the property to val.
-
#visible_params ⇒ Object
:nodoc:.
-
#year ⇒ Object
Returns the year (including the century).
Methods inherited from RiCal::PropertyValue
#==, convert, date_or_date_time, #enumerator, #equality_value, #for_parent, from_string, #initialize, #parms_string, #to_options_hash, #to_ri_cal_property_value, #to_s, #validate_value
Constructor Details
This class inherits a constructor from RiCal::PropertyValue
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(selector, *args) ⇒ Object
Delegate unknown messages to the wrappered Date instance. TODO: Is this really necessary?
107 108 109 |
# File 'lib/ri_cal/property_value/date.rb', line 107 def method_missing(selector, *args) #:nodoc: @date_time_value.send(selector, *args) end |
Instance Method Details
#add_date_times_to(required_timezones) ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/ri_cal/property_value/date.rb', line 100 def add_date_times_to(required_timezones) #:nodoc: # Do nothing since dates don't have a timezone end |
#advance(options) ⇒ Object
:nodoc:
92 93 94 |
# File 'lib/ri_cal/property_value/date.rb', line 92 def advance() #:nodoc: PropertyValue::Date.new(timezone_finder, :value => compute_advance(@date_time_value, ), :params =>(params ? params.dup : nil) ) end |
#change(options) ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/ri_cal/property_value/date.rb', line 96 def change() #:nodoc: PropertyValue::Date.new(timezone_finder,:value => compute_change(@date_time_value, ), :params => (params ? params.dup : nil) ) end |
#compute_advance(d, options) ⇒ Object
:nodoc:
84 85 86 87 88 89 90 |
# File 'lib/ri_cal/property_value/date.rb', line 84 def compute_advance(d, ) #:nodoc: d = d >> [:years] * 12 if [:years] d = d >> [:months] if [:months] d = d + [:weeks] * 7 if [:weeks] d = d + [:days] if [:days] compute_change(@date_time_value, :year => d.year, :month => d.month, :day => d.day) end |
#compute_change(d, options) ⇒ Object
:nodoc:
80 81 82 |
# File 'lib/ri_cal/property_value/date.rb', line 80 def compute_change(d, ) #:nodoc: ::Date.civil(([:year] || d.year), ([:month] || d.month), ([:day] || d.day)) end |
#day ⇒ Object
Returns the day of the month
54 55 56 |
# File 'lib/ri_cal/property_value/date.rb', line 54 def day @date_time_value.day end |
#month ⇒ Object
Returns the month of the year (1..12)
49 50 51 |
# File 'lib/ri_cal/property_value/date.rb', line 49 def month @date_time_value.month end |
#occurrence_hash(default_duration) ⇒ Object
TODO: consider if this should be a period rather than a hash
112 113 114 115 116 |
# File 'lib/ri_cal/property_value/date.rb', line 112 def occurrence_hash(default_duration) #:nodoc: date_time = self.to_ri_cal_date_time_value {:start => date_time, :end => date_time.advance(:hours => 24, :seconds => -1)} end |
#ruby_value ⇒ Object Also known as: to_ri_cal_ruby_value
Returns the ruby representation a ::Date
59 60 61 |
# File 'lib/ri_cal/property_value/date.rb', line 59 def ruby_value ::Date.parse(@date_time_value.strftime("%Y%m%d")) end |
#to_ri_cal_date_or_date_time_value ⇒ Object
Return the “Natural’ property value for the date_property, in this case the date property itself.”
76 77 78 |
# File 'lib/ri_cal/property_value/date.rb', line 76 def to_ri_cal_date_or_date_time_value self end |
#to_ri_cal_date_time_value ⇒ Object
Return an instance of RiCal::PropertyValue::DateTime representing the start of this date
66 67 68 |
# File 'lib/ri_cal/property_value/date.rb', line 66 def to_ri_cal_date_time_value PropertyValue::DateTime.new(:value => @date_time_value) end |
#to_ri_cal_date_value ⇒ Object
Return this date property
71 72 73 |
# File 'lib/ri_cal/property_value/date.rb', line 71 def to_ri_cal_date_value self end |
#value ⇒ Object
Returns the value of the reciever as an RFC 2445 iCalendar string
12 13 14 15 16 17 18 |
# File 'lib/ri_cal/property_value/date.rb', line 12 def value if @date_time_value @date_time_value.strftime("%Y%m%d") else nil end end |
#value=(val) ⇒ Object
Set the value of the property to val
val may be either:
-
A string which can be parsed as a DateTime
-
A Time instance
-
A Date instance
-
A DateTime instance
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ri_cal/property_value/date.rb', line 28 def value=(val) case val when nil @date_time_value = nil when String @date_time_value = ::DateTime.parse(::DateTime.parse(val).strftime("%Y%m%d")) when ::Time, ::Date, ::DateTime @date_time_value = ::DateTime.parse(val.strftime("%Y%m%d")) end end |
#visible_params ⇒ Object
:nodoc:
39 40 41 |
# File 'lib/ri_cal/property_value/date.rb', line 39 def visible_params #:nodoc: {"VALUE" => "DATE"}.merge(params) end |
#year ⇒ Object
Returns the year (including the century)
44 45 46 |
# File 'lib/ri_cal/property_value/date.rb', line 44 def year @date_time_value.year end |