class Tilia::VObject::Property::FloatValue

Float property.

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

Attributes

delimiter[RW]

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

@return [String, nil]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Tilia::VObject::Property::new
# File lib/tilia/v_object/property/float_value.rb, line 100
def initialize(*args)
  super(*args)
  @delimiter = ';'
end

Public Instance Methods

json_value() click to toggle source

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

This method must always return an array.

@return [array]

# 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_value() click to toggle source

Returns a raw mime-dir representation of the value.

@return [String]

# 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) click to toggle source

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.

@param [String] val

@return [void]

# 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_type() click to toggle source

Returns the type of value.

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

@return [String]

# File lib/tilia/v_object/property/float_value.rb, line 42
def value_type
  'FLOAT'
end
xml_value=(value) click to toggle source

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

@param [array] value

@return [void]

Calls superclass method Tilia::VObject::Property#xml_value=
# 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

Protected Instance Methods

xml_serialize_value(writer) click to toggle source

This method serializes only the value of a property. This is used to create xCard or xCal documents.

@param [XmlWriter] writer XML writer.

@return [void]

# File lib/tilia/v_object/property/float_value.rb, line 83
def xml_serialize_value(writer)
  # Special-casing the GEO property.
  #
  # See:
  # http://tools.ietf.org/html/rfc6321#section-3.4.1.2
  if @name == 'GEO'
    value = parts.map(&:to_f)

    writer.write_element('latitude', value[0])
    writer.write_element('longitude', value[1])
  else
    super(writer)
  end
end