Class: Nanaimo::Reader
- Inherits:
-
Object
- Object
- Nanaimo::Reader
- Defined in:
- lib/nanaimo/reader.rb
Overview
Transforms plist strings into Plist objects.
Defined Under Namespace
Classes: ParseError, UnsupportedPlistFormatError
Class Method Summary collapse
-
.from_file(file_path) ⇒ Plist
A parsed plist from the given file.
-
.plist_type(plist_contents) ⇒ Symbol
The file format of the plist in the given string.
Instance Method Summary collapse
-
#initialize(contents) ⇒ Reader
constructor
A new instance of Reader.
-
#parse! ⇒ Plist
Parses the contents of the plist.
Constructor Details
#initialize(contents) ⇒ Reader
Returns a new instance of Reader.
96 97 98 |
# File 'lib/nanaimo/reader.rb', line 96 def initialize(contents) @scanner = StringScanner.new(contents) end |
Class Method Details
.from_file(file_path) ⇒ Plist
Returns A parsed plist from the given file.
90 91 92 |
# File 'lib/nanaimo/reader.rb', line 90 def self.from_file(file_path) new(File.read(file_path)) end |
.plist_type(plist_contents) ⇒ Symbol
Returns The file format of the plist in the given string.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nanaimo/reader.rb', line 75 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
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/nanaimo/reader.rb', line 104 def parse! plist_format = ensure_ascii_plist! read_string_encoding root_object = parse_object eat_whitespace! raise_parser_error ParseError, 'Found additional characters after parsing the root plist object' unless @scanner.eos? Nanaimo::Plist.new(root_object, plist_format) end |