Class: Icalendar::Value

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/icalendar/value.rb

Constant Summary collapse

VALUE_TYPE_GSUB_REGEX_1 =
/\A.*::/.freeze
VALUE_TYPE_GSUB_REGEX_2 =
/(?<!\A)[A-Z]/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Value.



13
14
15
16
# File 'lib/icalendar/value.rb', line 13

def initialize(value, params = {})
  @ical_params = Icalendar::DowncasedHash(params)
  super value
end

Instance Attribute Details

#ical_paramsObject

Returns the value of attribute ical_params.



11
12
13
# File 'lib/icalendar/value.rb', line 11

def ical_params
  @ical_params
end

Class Method Details

.value_typeObject



40
41
42
# File 'lib/icalendar/value.rb', line 40

def self.value_type
  name.gsub(VALUE_TYPE_GSUB_REGEX_1, '').gsub(VALUE_TYPE_GSUB_REGEX_2, '-\0').upcase
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/icalendar/value.rb', line 48

def ==(other)
  if other.is_a?(Icalendar::Value)
    super(other.value) && ical_params == other.ical_params
  else
    super
  end
end

#ical_param(key, value) ⇒ Object



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

def ical_param(key, value)
  @ical_params[key] = value
end

#params_icalObject



31
32
33
34
35
# File 'lib/icalendar/value.rb', line 31

def params_ical
  unless ical_params.empty?
    ";#{ical_params.map { |name, value| param_ical name, value }.join ';'}"
  end
end

#to_ical(default_type) ⇒ Object



26
27
28
29
# File 'lib/icalendar/value.rb', line 26

def to_ical(default_type)
  ical_param 'value', self.value_type if needs_value_type?(default_type)
  "#{params_ical}:#{value_ical}"
end

#valueObject



22
23
24
# File 'lib/icalendar/value.rb', line 22

def value
  __getobj__
end

#value_typeObject



44
45
46
# File 'lib/icalendar/value.rb', line 44

def value_type
  self.class.value_type
end