Class: Tilia::VObject::Parser::MimeDir
- Defined in:
- lib/tilia/v_object/parser/mime_dir.rb
Overview
MimeDir parser.
This class parses iCalendar 2.0 and vCard 2.1, 3.0 and 4.0 files. This parser will return one of the following two objects from the parse method:
SabreVObjectComponentVCalendar SabreVObjectComponentVCard
Constant Summary
Constants inherited from Parser
Parser::OPTION_FORGIVING, Parser::OPTION_IGNORE_INVALID_LINES
Class Attribute Summary collapse
-
.supported_charsets ⇒ Object
readonly
Returns the value of attribute supported_charsets.
Instance Method Summary collapse
-
#charset=(charset) ⇒ Object
By default all input will be assumed to be UTF-8.
-
#input=(input) ⇒ void
Sets the input buffer.
-
#parse(input = nil, options = 0) ⇒ Document
Parses an iCalendar or vCard file.
Class Attribute Details
.supported_charsets ⇒ Object (readonly)
Returns the value of attribute supported_charsets.
23 24 25 |
# File 'lib/tilia/v_object/parser/mime_dir.rb', line 23 def supported_charsets @supported_charsets end |
Instance Method Details
#charset=(charset) ⇒ Object
By default all input will be assumed to be UTF-8.
However, both iCalendar and vCard might be encoded using different character sets. The character set is usually set in the mime-type.
If this is the case, use setEncoding to specify that a different encoding will be used. If this is set, the parser will automatically convert all incoming data to UTF-8.
56 57 58 59 60 |
# File 'lib/tilia/v_object/parser/mime_dir.rb', line 56 def charset=(charset) fail ArgumentError, "Unsupported encoding. (Supported encodings: #{MimeDir.supported_charsets.join(', ')})" unless MimeDir.supported_charsets.include?(charset) @charset = charset end |
#input=(input) ⇒ void
This method returns an undefined value.
Sets the input buffer. Must be a string or stream.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tilia/v_object/parser/mime_dir.rb', line 67 def input=(input) # Resetting the parser @line_index = 0 @start_line = 0 if input.is_a?(String) # Convering to a stream. stream = StringIO.new stream.write(input) stream.rewind @input = stream elsif input.respond_to?(:read) @input = input else fail ArgumentError, 'This parser can only read from strings or streams.' end end |
#parse(input = nil, options = 0) ⇒ Document
Parses an iCalendar or vCard file.
Pass a stream or a string. If null is parsed, the existing buffer is used.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tilia/v_object/parser/mime_dir.rb', line 35 def parse(input = nil, = 0) @root = nil self.input = input unless input.nil? @options = if != 0 parse_document @root end |