Class: Nanaimo::Reader

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

Overview

Transforms plist strings into Plist objects.

Defined Under Namespace

Classes: ParseError, UnsupportedPlistFormatError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Reader



62
63
64
# File 'lib/nanaimo/reader.rb', line 62

def initialize(contents)
  @scanner = StringScanner.new(contents)
end

Class Method Details

.from_file(file_path) ⇒ Plist



56
57
58
# File 'lib/nanaimo/reader.rb', line 56

def self.from_file(file_path)
  new(File.read(file_path))
end

.plist_type(plist_contents) ⇒ Symbol



41
42
43
44
45
46
47
48
49
50
# File 'lib/nanaimo/reader.rb', line 41

def self.plist_type(plist_contents)
  case plist_contents
  when /\Abplist/
    :binary
  when /\A<\?xml/
    :xml
  else
    :ascii
  end
end

Instance Method Details

#parse!Plist

Parses the contents of the plist



70
71
72
73
74
75
76
77
78
79
# File 'lib/nanaimo/reader.rb', line 70

def parse!
  plist_format = ensure_ascii_plist!
  read_string_encoding
  root_object = parse_object

  eat_whitespace!
  raise_parser_error ParseError, "unrecognized characters #{@scanner.rest.inspect} after parsing" unless @scanner.eos?

  Nanaimo::Plist.new(root_object, plist_format)
end