Class: Tilia::VObject::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/tilia/v_object/reader.rb

Overview

iCalendar/vCard/jCal/jCard/xCal/xCard reader object.

This object provides a few (static) convenience methods to quickly access the parsers.

Constant Summary collapse

OPTION_FORGIVING =

If this option is passed to the reader, it will be less strict about the validity of the lines.

1
OPTION_IGNORE_INVALID_LINES =

If this option is turned on, any lines we cannot parse will be ignored by the reader.

2

Class Method Summary collapse

Class Method Details

.read(data, options = 0, charset = 'UTF-8') ⇒ Document

Parses a vCard or iCalendar object, and returns the top component.

The options argument is a bitfield. Pass any of the OPTIONS constant to alter the parsers’ behaviour.

You can either supply a string, or a readable stream for input.

Parameters:

  • data (String, #read)
  • options (Fixnum) (defaults to: 0)
  • charset (String) (defaults to: 'UTF-8')

Returns:



27
28
29
30
31
32
33
# File 'lib/tilia/v_object/reader.rb', line 27

def self.read(data, options = 0, charset = 'UTF-8')
  parser = Parser::MimeDir.new
  parser.charset = charset
  result = parser.parse(data, options)

  result
end

.read_json(data, options = 0) ⇒ Document

Parses a jCard or jCal object, and returns the top component.

The options argument is a bitfield. Pass any of the OPTIONS constant to alter the parsers’ behaviour.

You can either a string, a readable stream, or an array for it’s input. Specifying the array is useful if json_decode was already called on the input.

Parameters:

  • data (String, |resource|array)
  • options (Fixnum) (defaults to: 0)

Returns:



48
49
50
51
52
53
# File 'lib/tilia/v_object/reader.rb', line 48

def self.read_json(data, options = 0)
  parser = Parser::Json.new
  result = parser.parse(data, options)

  result
end

.read_xml(data, options = 0) ⇒ Document

Parses a xCard or xCal object, and returns the top component.

The options argument is a bitfield. Pass any of the OPTIONS constant to alter the parsers’ behaviour.

You can either supply a string, or a readable stream for input.

Parameters:

  • data (String|resource)
  • options (Fixnum) (defaults to: 0)

Returns:



66
67
68
69
70
71
# File 'lib/tilia/v_object/reader.rb', line 66

def self.read_xml(data, options = 0)
  parser = Parser::Xml.new
  result = parser.parse(data, options)

  result
end