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

Constructor Details

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



8
9
10
# File 'lib/icalendar/values/duration.rb', line 8

def initialize(value, params = {})
  super OpenStruct.new(parse_fields value), params
end

Instance Method Details

#past?Boolean



12
13
14
# File 'lib/icalendar/values/duration.rb', line 12

def past?
  value.past
end

#value_icalObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/icalendar/values/duration.rb', line 16

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