Class: Icalendar::Values::Duration

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

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, #value_type

Constructor Details

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

Returns a new instance of Duration.



8
9
10
11
12
13
14
# File 'lib/icalendar/values/duration.rb', line 8

def initialize(value, params = {})
  if value.is_a? Icalendar::Values::Duration
    super value.value, params
  else
    super OpenStruct.new(parse_fields value), params
  end
end

Instance Method Details

#past?Boolean

Returns:



16
17
18
# File 'lib/icalendar/values/duration.rb', line 16

def past?
  value.past
end

#value_icalObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/icalendar/values/duration.rb', line 20

def value_ical
  return "#{'-' if past?}P#{weeks}W" if weeks > 0
  builder = []
  builder << '-' if past?
  builder << 'P'
  builder << "#{days}D" if days > 0
  builder << 'T' if time?
  builder << "#{hours}H" if hours > 0
  builder << "#{minutes}M" if minutes > 0
  builder << "#{seconds}S" if seconds > 0
  builder.join
end