Class: Icalendar::Values::Period

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

Constant Summary collapse

PERIOD_LAST_PART_REGEX =
/\A[+-]?P.+\z/.freeze

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 = {}) ⇒ Period

Returns a new instance of Period.



10
11
12
13
14
15
16
17
18
19
# File 'lib/icalendar/values/period.rb', line 10

def initialize(value, params = {})
  parts = value.split '/'
  period_start = Icalendar::Values::DateTime.new parts.first
  if parts.last =~ PERIOD_LAST_PART_REGEX
    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



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

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

#duration=(v) ⇒ Object



45
46
47
# File 'lib/icalendar/values/period.rb', line 45

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

#explicit_endObject



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

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

#explicit_end=(v) ⇒ Object



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

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

#period_startObject



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

def period_start
  first
end

#period_start=(v) ⇒ Object



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

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

#value_icalObject



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

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