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.
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
Returns A parsed plist from the given file.
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
Returns The file format of the plist in the given string.
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 |