Class: Icalendar::Values::Period

Inherits:
Icalendar::Value show all
Defined in:
lib/icalendar/values/period.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 = {}) ⇒ Period

Returns a new instance of Period.


6
7
8
9
10
11
12
13
14
15
# File 'lib/icalendar/values/period.rb', line 6

def initialize(value, params = {})
  parts = value.split '/'
  period_start = Icalendar::Values::DateTime.new parts.first
  if parts.last =~ /\A[+-]?P.+\z/
    period_end = Icalendar::Values::Duration.new parts.last
  else
    period_end = Icalendar::Values::DateTime.new parts.last
  end
  super [period_start, period_end], params
end

Instance Method Details

#durationObject


37
38
39
# File 'lib/icalendar/values/period.rb', line 37

def duration
  last.is_a?(Icalendar::Values::Duration) ? last : nil
end

#duration=(v) ⇒ Object


41
42
43
# File 'lib/icalendar/values/period.rb', line 41

def duration=(v)
  value[1] = v.is_a?(Icalendar::Values::Duration) ? v : Icalendar::Values::Duration.new(v)
end

#explicit_endObject


29
30
31
# File 'lib/icalendar/values/period.rb', line 29

def explicit_end
  last.is_a?(Icalendar::Values::DateTime) ? last : nil
end

#explicit_end=(v) ⇒ Object


33
34
35
# File 'lib/icalendar/values/period.rb', line 33

def explicit_end=(v)
  value[1] = v.is_a?(Icalendar::Values::DateTime) ? v : Icalendar::Values::DateTime.new(v)
end

#period_startObject


21
22
23
# File 'lib/icalendar/values/period.rb', line 21

def period_start
  first
end

#period_start=(v) ⇒ Object


25
26
27
# File 'lib/icalendar/values/period.rb', line 25

def period_start=(v)
  value[0] = v.is_a?(Icalendar::Values::DateTime) ? v : Icalendar::Values::DateTime.new(v)
end

#value_icalObject


17
18
19
# File 'lib/icalendar/values/period.rb', line 17

def value_ical
  value.map { |v| v.value_ical }.join '/'
end