Class: Tilia::VObject::Property::FloatValue

Inherits:
Tilia::VObject::Property show all
Defined in:
lib/tilia/v_object/property/float_value.rb

Overview

Float property.

This object represents FLOAT values. These can be 1 or more floating-point numbers.

Constant Summary

Constants inherited from Node

Node::PROFILE_CALDAV, Node::PROFILE_CARDDAV, Node::REPAIR

Instance Attribute Summary collapse

Attributes inherited from Tilia::VObject::Property

#group, #name, #parameters, #value

Attributes inherited from Node

#iterator, #parent

Instance Method Summary collapse

Methods inherited from Tilia::VObject::Property

#==, #[], #[]=, #add, #delete, #destroy, #initialize_copy, #json_serialize, #json_value=, #key?, #parts, #parts=, #serialize, #to_s, #validate, #xml_serialize

Methods inherited from Node

#==, #[], #[]=, #delete, #destroy, #each, #json_serialize, #key?, #serialize, #size, #validate, #xml_serialize

Constructor Details

#initialize(*args) ⇒ FloatValue

Returns a new instance of FloatValue.



100
101
102
103
# File 'lib/tilia/v_object/property/float_value.rb', line 100

def initialize(*args)
  super(*args)
  @delimiter = ';'
end

Instance Attribute Details

#delimiterString?

In case this is a multi-value property. This string will be used as a delimiter.

Returns:

  • (String, nil)


13
14
15
# File 'lib/tilia/v_object/property/float_value.rb', line 13

def delimiter
  @delimiter
end

Instance Method Details

#json_valuearray

Returns the value, in the format it should be encoded for JSON.

This method must always return an array.

Returns:

  • (array)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tilia/v_object/property/float_value.rb', line 51

def json_value
  val = parts.map(&:to_f)

  # Special-casing the GEO property.
  #
  # See:
  # http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
  return [val] if @name == 'GEO'

  val
end

#raw_mime_dir_valueString

Returns a raw mime-dir representation of the value.

Returns:

  • (String)


32
33
34
# File 'lib/tilia/v_object/property/float_value.rb', line 32

def raw_mime_dir_value
  parts.join(@delimiter)
end

#raw_mime_dir_value=(val) ⇒ void

This method returns an undefined value.

Sets a raw value coming from a mimedir (iCalendar/vCard) file.

This has been ‘unfolded’, so only 1 line will be passed. Unescaping is not yet done, but parameters are not included.

Parameters:

  • val (String)


23
24
25
26
27
# File 'lib/tilia/v_object/property/float_value.rb', line 23

def raw_mime_dir_value=(val)
  val = val.split(@delimiter)
  val = val.map(&:to_f)
  self.parts = val
end

#value_typeString

Returns the type of value.

This corresponds to the VALUE= parameter. Every property also has a ‘default’ valueType.

Returns:

  • (String)


42
43
44
# File 'lib/tilia/v_object/property/float_value.rb', line 42

def value_type
  'FLOAT'
end

#xml_value=(value) ⇒ void

This method returns an undefined value.

Hydrate data from a XML subtree, as it would appear in a xCard or xCal object.

Parameters:

  • value (array)


69
70
71
72
73
# File 'lib/tilia/v_object/property/float_value.rb', line 69

def xml_value=(value)
  value = value.values if value.is_a?(Hash)
  value = value.map(&:to_f)
  super(value)
end