Class: RiCal::PropertyValue::Duration
- Inherits:
-
RiCal::PropertyValue
- Object
- RiCal::PropertyValue
- RiCal::PropertyValue::Duration
- Defined in:
- lib/ri_cal/property_value/duration.rb
Overview
-
©2009 Rick DeNatale
-
All rights reserved. Refer to the file README.txt for the license
RiCal::PropertyValue::CalAddress represents an icalendar Duration property value which is defined in rfc 2445 section 4.3.6 p 37
Instance Attribute Summary
Attributes inherited from RiCal::PropertyValue
#params, #timezone_finder, #value
Class Method Summary collapse
-
.convert(parent, ruby_object) ⇒ Object
:nodoc:.
-
.from_datetimes(parent, start, finish, sign = '+') ⇒ Object
:nodoc:.
-
.value_part(unit, diff) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Determine whether another object is an equivalent RiCal::PropertyValue::Duration.
-
#add_to_date_time_value(date_time_value) ⇒ Object
Double-dispatch method to support RiCal::PropertyValue::DateTime.+.
-
#days ⇒ Object
:nodoc:.
-
#hours ⇒ Object
:nodoc:.
-
#minutes ⇒ Object
:nodoc:.
-
#seconds ⇒ Object
:nodoc:.
-
#subtract_from_date_time_value(date_time_value) ⇒ Object
Double-dispatch method to support RiCal::PropertyValue::DateTime.-.
-
#to_ri_cal_duration_value ⇒ Object
Returns the receiver.
-
#value=(string) ⇒ Object
:nodoc:.
-
#weeks ⇒ Object
:nodoc:.
Methods inherited from RiCal::PropertyValue
#add_date_times_to, date_or_date_time, #enumerator, #equality_value, #for_parent, from_string, #initialize, #parms_string, #ruby_value, #to_options_hash, #to_ri_cal_property_value, #to_s, #validate_value, #visible_params
Constructor Details
This class inherits a constructor from RiCal::PropertyValue
Class Method Details
.convert(parent, ruby_object) ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/ri_cal/property_value/duration.rb', line 36 def self.convert(parent, ruby_object) # :nodoc: ruby_object.to_ri_cal_duration_value.for_parent(parent) end |
.from_datetimes(parent, start, finish, sign = '+') ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ri_cal/property_value/duration.rb', line 15 def self.from_datetimes(parent, start, finish, sign='+') # :nodoc: if start > finish from_datetimes(finish, start, '-') else diff = finish - start days_diff = diff.to_i hours = (diff - days_diff) * 24 hour_diff = hours.to_i minutes = (hours - hour_diff) * 60 min_diff = minutes.to_i seconds = (minutes - min_diff) * 60 sec_diff = seconds.to_i day_part = value_part('D',days_diff) hour_part = value_part('H', hour_diff) min_part = value_part('M', min_diff) sec_part = value_part('S', sec_diff) new(parent, :value => "#{sign}P#{day_part}T#{day_part}#{hour_part}#{min_part}#{sec_part}") end end |
.value_part(unit, diff) ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/ri_cal/property_value/duration.rb', line 11 def self.value_part(unit, diff) # :nodoc: (diff == 0) ? nil : "#{diff}#{unit}" end |
Instance Method Details
#==(other) ⇒ Object
Determine whether another object is an equivalent RiCal::PropertyValue::Duration
85 86 87 |
# File 'lib/ri_cal/property_value/duration.rb', line 85 def ==(other) other.kind_of?(PropertyValue::Duration) && value == other.value end |
#add_to_date_time_value(date_time_value) ⇒ Object
Double-dispatch method to support RiCal::PropertyValue::DateTime.+
100 101 102 |
# File 'lib/ri_cal/property_value/duration.rb', line 100 def add_to_date_time_value(date_time_value) date_time_value.advance(:weeks => weeks, :days => days, :hours => hours, :minutes => minutes, :seconds => seconds) end |
#days ⇒ Object
:nodoc:
64 65 66 |
# File 'lib/ri_cal/property_value/duration.rb', line 64 def days # :nodoc: @days * @sign end |
#hours ⇒ Object
:nodoc:
72 73 74 |
# File 'lib/ri_cal/property_value/duration.rb', line 72 def hours # :nodoc: @hours * @sign end |
#minutes ⇒ Object
:nodoc:
76 77 78 |
# File 'lib/ri_cal/property_value/duration.rb', line 76 def minutes # :nodoc: @minutes * @sign end |
#seconds ⇒ Object
:nodoc:
80 81 82 |
# File 'lib/ri_cal/property_value/duration.rb', line 80 def seconds # :nodoc: @seconds * @sign end |
#subtract_from_date_time_value(date_time_value) ⇒ Object
Double-dispatch method to support RiCal::PropertyValue::DateTime.-
95 96 97 |
# File 'lib/ri_cal/property_value/duration.rb', line 95 def subtract_from_date_time_value(date_time_value) date_time_value.advance(:weeks => -weeks, :days => -days, :hours => -hours, :minutes => -minutes, :seconds => -seconds) end |
#to_ri_cal_duration_value ⇒ Object
Returns the receiver
90 91 92 |
# File 'lib/ri_cal/property_value/duration.rb', line 90 def to_ri_cal_duration_value self end |
#value=(string) ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ri_cal/property_value/duration.rb', line 40 def value=(string) # :nodoc: super match = /([+-])?P(.*)$/.match(string) @days = @hours = @minutes = @seconds = @weeks = 0 if match @sign = match[1] == '-' ? -1 : 1 match[2].scan(/(\d+)([DHMSW])/) do |digits, unit| number = digits.to_i case unit when 'D' @days = number when 'H' @hours = number when 'M' @minutes = number when 'S' @seconds = number when 'W' @weeks = number end end end end |
#weeks ⇒ Object
:nodoc:
68 69 70 |
# File 'lib/ri_cal/property_value/duration.rb', line 68 def weeks # :nodoc: @weeks * @sign end |