Class: Tilia::VObject::Property::ICalendar::Period
- Inherits:
-
Tilia::VObject::Property
- Object
- Node
- Tilia::VObject::Property
- Tilia::VObject::Property::ICalendar::Period
- Defined in:
- lib/tilia/v_object/property/i_calendar/period.rb
Overview
Period property.
This object represents PERIOD values, as defined here:
Constant Summary
Constants inherited from Node
Node::PROFILE_CALDAV, Node::PROFILE_CARDDAV, Node::REPAIR
Instance Attribute Summary collapse
-
#delimiter ⇒ String?
In case this is a multi-value property.
Attributes inherited from Tilia::VObject::Property
#group, #name, #parameters, #value
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(*args) ⇒ Period
constructor
A new instance of Period.
-
#json_value ⇒ array
Returns the value, in the format it should be encoded for json.
-
#json_value=(value) ⇒ void
Sets the json value, as it would appear in a jCard or jCal object.
-
#raw_mime_dir_value ⇒ String
Returns a raw mime-dir representation of the value.
-
#raw_mime_dir_value=(val) ⇒ void
Sets a raw value coming from a mimedir (iCalendar/vCard) file.
-
#value_type ⇒ String
Returns the type of value.
Methods inherited from Tilia::VObject::Property
#==, #[], #[]=, #add, #delete, #destroy, #initialize_copy, #json_serialize, #key?, #parts, #parts=, #serialize, #to_s, #validate, #xml_serialize, #xml_value=
Methods inherited from Node
#==, #[], #[]=, #delete, #destroy, #each, #json_serialize, #key?, #serialize, #size, #validate, #xml_serialize
Constructor Details
#initialize(*args) ⇒ Period
Returns a new instance of Period.
116 117 118 119 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 116 def initialize(*args) super(*args) @delimiter = ',' end |
Instance Attribute Details
#delimiter ⇒ String?
In case this is a multi-value property. This string will be used as a delimiter.
15 16 17 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 15 def delimiter @delimiter end |
Instance Method Details
#json_value ⇒ array
Returns the value, in the format it should be encoded for json.
This method must always return an array.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 67 def json_value result = [] parts.each do |item| (start, ending) = item.split('/', 2) start = Tilia::VObject::DateTimeParser.parse_date_time(start) # This is a duration value. if ending[0] == 'P' result << [ start.strftime('%Y-%m-%dT%H:%M:%S'), ending ] else ending = Tilia::VObject::DateTimeParser.parse_date_time(ending) result << [ start.strftime('%Y-%m-%dT%H:%M:%S'), ending.strftime('%Y-%m-%dT%H:%M:%S') ] end end result 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.
53 54 55 56 57 58 59 60 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 53 def json_value=(value) value = value.values if value.is_a?(Hash) value = value.map do |item| item = item.values if item.is_a?(Hash) item.join('/').delete(':').delete('-') end super(value) end |
#raw_mime_dir_value ⇒ String
Returns a raw mime-dir representation of the value.
32 33 34 |
# File 'lib/tilia/v_object/property/i_calendar/period.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.
25 26 27 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 25 def raw_mime_dir_value=(val) self.value = val.split(@delimiter) end |
#value_type ⇒ String
Returns the type of value.
This corresponds to the VALUE= parameter. Every property also has a ‘default’ valueType.
42 43 44 |
# File 'lib/tilia/v_object/property/i_calendar/period.rb', line 42 def value_type 'PERIOD' end |