Class: Tilia::VObject::Property::Time

Inherits:
Text show all
Defined in:
lib/tilia/v_object/property/time.rb

Overview

Time property.

This object encodes TIME values.

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 Text

#quoted_printable_value=, #raw_mime_dir_value, #raw_mime_dir_value=, #serialize, #validate

Methods inherited from Tilia::VObject::Property

#==, #[], #[]=, #add, #delete, #destroy, #initialize_copy, #json_serialize, #key?, #parts, #parts=, #raw_mime_dir_value, #raw_mime_dir_value=, #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) ⇒ Time

Returns a new instance of Time.



101
102
103
104
# File 'lib/tilia/v_object/property/time.rb', line 101

def initialize(*args)
  super(*args)
  @delimiter = nil
end

Instance Attribute Details

#delimiterString?

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

Returns:

  • (String, nil)


12
13
14
# File 'lib/tilia/v_object/property/time.rb', line 12

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)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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) ⇒ void

This method returns an undefined value.

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

The value must always be an array.

Parameters:

  • value (array)


30
31
32
33
34
35
36
37
38
39
# 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_typeString

Returns the type of value.

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

Returns:

  • (String)


20
21
22
# File 'lib/tilia/v_object/property/time.rb', line 20

def value_type
  'TIME'
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)


94
95
96
97
98
99
# 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