Class: Icalendar::Values::Helpers::Array

Inherits:
Icalendar::Value show all
Defined in:
lib/icalendar/values/helpers/array.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 collapse

Attributes inherited from Icalendar::Value

#ical_params

Instance Method Summary collapse

Methods inherited from Icalendar::Value

#==, #ical_param, #to_ical, #value, value_type

Constructor Details

#initialize(value, klass, params = {}, options = {}) ⇒ Array

Returns a new instance of Array.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/icalendar/values/helpers/array.rb', line 11

def initialize(value, klass, params = {}, options = {})
  @value_delimiter = options[:delimiter] || ','
  mapped = if value.is_a? ::Array
            value.map do |v|
              if v.is_a? Icalendar::Values::Helpers::Array
                Icalendar::Values::Helpers::Array.new v.value, klass, v.ical_params, delimiter: v.value_delimiter
              elsif v.is_a? ::Array
                Icalendar::Values::Helpers::Array.new v, klass, params, delimiter: value_delimiter
              elsif v.is_a? Icalendar::Value
                v
              else
                klass.new v, params
              end
            end
          else
            [klass.new(value, params)]
          end
  super mapped
end

Instance Attribute Details

#value_delimiterObject (readonly)

Returns the value of attribute value_delimiter.



9
10
11
# File 'lib/icalendar/values/helpers/array.rb', line 9

def value_delimiter
  @value_delimiter
end

Instance Method Details

#params_icalObject



31
32
33
34
35
36
# File 'lib/icalendar/values/helpers/array.rb', line 31

def params_ical
  value.each do |v|
    ical_params.merge! v.ical_params
  end
  super
end

#valid?Boolean

Returns:



44
45
46
47
# File 'lib/icalendar/values/helpers/array.rb', line 44

def valid?
  klass = value.first.class
  !value.all? { |v| v.class == klass }
end

#value_icalObject



38
39
40
41
42
# File 'lib/icalendar/values/helpers/array.rb', line 38

def value_ical
  value.map do |v|
    v.value_ical
  end.join value_delimiter
end

#value_typeObject



49
50
51
# File 'lib/icalendar/values/helpers/array.rb', line 49

def value_type
  value.first.value_type
end