Class: Icalendar::Values::Duration

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

Constant Summary

Constants inherited from Icalendar::Value

Icalendar::Value::VALUE_TYPE_GSUB_REGEX_1, Icalendar::Value::VALUE_TYPE_GSUB_REGEX_2

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.



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

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:



18
19
20
# File 'lib/icalendar/values/duration.rb', line 18

def past?
  value.past
end

#value_icalObject



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

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