Class: Tilia::VObject::Parser::Xml
- Inherits:
-
Tilia::VObject::Parser
- Object
- Tilia::VObject::Parser
- Tilia::VObject::Parser::Xml
- Defined in:
- lib/tilia/v_object/parser/xml.rb,
lib/tilia/v_object/parser/xml/element.rb,
lib/tilia/v_object/parser/xml/element/key_value.rb
Overview
XML Parser.
This parser parses both the xCal and xCard formats.
Defined Under Namespace
Modules: Element
Constant Summary collapse
- XCAL_NAMESPACE =
'urn:ietf:params:xml:ns:icalendar-2.0'
- XCARD_NAMESPACE =
'urn:ietf:params:xml:ns:vcard-4.0'
Class Method Summary collapse
-
.tag_name(clarked_tag_name) ⇒ String
Get tag name from a Clark notation.
Instance Method Summary collapse
-
#initialize(input = nil, options = 0) ⇒ void
constructor
Creates the parser.
-
#input=(input) ⇒ void
Sets the input data.
-
#parse(input = nil, options = 0) ⇒ Document
Parse xCal or xCard.
Constructor Details
#initialize(input = nil, options = 0) ⇒ void
Creates the parser.
Optionally, it’s possible to parse the input stream here.
21 22 23 24 25 26 27 28 29 |
# File 'lib/tilia/v_object/parser/xml.rb', line 21 def initialize(input = nil, = 0) @input = nil @pointer = nil @root = nil = OPTION_FORGIVING if == 0 super(input, ) end |
Class Method Details
.tag_name(clarked_tag_name) ⇒ String
Get tag name from a Clark notation.
298 299 300 301 |
# File 'lib/tilia/v_object/parser/xml.rb', line 298 def self.tag_name(clarked_tag_name) (_, tag_name) = Tilia::Xml::Service.parse_clark_notation(clarked_tag_name) tag_name end |
Instance Method Details
#input=(input) ⇒ void
This method returns an undefined value.
Sets the input data.
279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/tilia/v_object/parser/xml.rb', line 279 def input=(input) input = input.read unless input.is_a?(String) if input.is_a?(String) reader = Tilia::Xml::Reader.new reader.element_map["{#{XCAL_NAMESPACE}}period"] = Tilia::VObject::Parser::Xml::Element::KeyValue reader.element_map["{#{XCAL_NAMESPACE}}recur"] = Tilia::VObject::Parser::Xml::Element::KeyValue reader.xml(input) input = reader.parse end @input = input end |
#parse(input = nil, options = 0) ⇒ Document
Parse xCal or xCard.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tilia/v_object/parser/xml.rb', line 39 def parse(input = nil, = 0) self.input = input unless input.nil? @options = if != 0 if @input.nil? fail Tilia::VObject::EofException, 'End of input stream, or no input supplied' end case @input['name'] when "{#{XCAL_NAMESPACE}}icalendar" @root = Tilia::VObject::Component::VCalendar.new({}, false) @pointer = @input['value'][0] parse_v_calendar_components(@root) when "{#{XCARD_NAMESPACE}}vcards" @input['value'].each do |v_card| @root = Tilia::VObject::Component::VCard.new({ 'version' => '4.0' }, false) @pointer = v_card parse_v_card_components(@root) # We just parse the first <vcard /> element. break end else fail Tilia::VObject::ParseException, 'Unsupported XML standard' end @root end |