Class: CFPropertyList::PlainParser

Inherits:
XMLParserInterface show all
Defined in:
lib/cfpropertylist/rbPlainCFPropertyList.rb

Overview

XML parser

Constant Summary collapse

SPACES_AND_COMMENTS =
%r{((?:/\*.*?\*/)|(?://.*?$\n?)|(?:\s*))+}x

Instance Method Summary collapse

Methods inherited from XMLParserInterface

#append_node, #new_node, #new_text

Instance Method Details

#load(opts) ⇒ Object

read a XML file

opts
  • :file - The filename of the file to load

  • :data - The data to parse

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cfpropertylist/rbPlainCFPropertyList.rb', line 12

def load(opts)
  @doc = nil

  if(opts.has_key?(:file)) then
    File.open(opts[:file], :external_encoding => "ASCII") do |fd|
      @doc = StringScanner.new(fd.read)
    end
  else
    @doc = StringScanner.new(opts[:data])
  end

  if @doc
    root = import_plain
    raise CFFormatError.new('content after root object') unless @doc.eos?

    return root
  end

  raise CFFormatError.new('invalid plist string or file not found')
end

#to_str(opts = {}) ⇒ Object

serialize CFPropertyList object to XML

opts = {}

Specify options: :formatted - Use indention and line breaks



37
38
39
# File 'lib/cfpropertylist/rbPlainCFPropertyList.rb', line 37

def to_str(opts={})
  opts[:root].to_plain(self)
end