class Tilia::VObject::Property::Time

Time property.

This object encodes TIME values.

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::Text::new
# File lib/tilia/v_object/property/time.rb, line 101
def initialize(*args)
  super(*args)
  @delimiter = nil
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/time.rb, line 46
def json_value
  parts = DateTimeParser.parse_v_card_time(value)
  time_str = ''

  # Hour
  if !parts['hour'].nil?
    time_str += parts['hour']

    time_str += ':' unless parts['minute'].nil?
  else
    # We know either minute or second _must_ be set, so we insert a
    # dash for an empty value.
    time_str += '-'
  end

  # Minute
  if !parts['minute'].nil?
    time_str += parts['minute']

    time_str += ':' unless parts['second'].nil?
  else
    if parts['second']
      # Dash for empty minute
      time_str += '-'
    end
  end

  # Second
  time_str += parts['second'] unless parts['second'].nil?

  # Timezone
  unless parts['timezone'].nil?
    if parts['timezone'] == 'Z'
      time_str += 'Z'
    else
      time_str += parts['timezone'].gsub(/([0-9]{2})([0-9]{2})$/) { "#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" }
    end
  end

  [time_str]
end
json_value=(value) click to toggle source

Sets the JSON value, as it would appear in a jCard or jCal object.

The value must always be an array.

@param [array] value @return [void]

# File lib/tilia/v_object/property/time.rb, line 30
def json_value=(value)
  # Removing colons from value.
  value = value.map { |v| v.delete(':') }

  if value.size == 1
    self.value = value.first
  else
    self.value = value
  end
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/time.rb, line 20
def value_type
  'TIME'
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/time.rb, line 94
def xml_value=(value)
  value = value.map do |v|
    v.delete(':')
  end
  super(value)
end