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 = {}, context = {}) ⇒ Value

Returns a new instance of Value.



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

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

Instance Attribute Details

#contextObject

Returns the value of attribute context.



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

def context
  @context
end

#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



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

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



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

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



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

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

#params_icalObject



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

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

#to_ical(default_type) ⇒ Object



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

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

#valueObject



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

def value
  __getobj__
end

#value_typeObject



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

def value_type
  self.class.value_type
end