Class: Vendor::Plist::AsciiParser
- Inherits:
-
StringScanner
- Object
- StringScanner
- Vendor::Plist::AsciiParser
- Defined in:
- lib/vendor/plist.rb
Overview
Plist::AsciiParser
Parser for the old style ASCII/NextSTEP property lists.
Created by Jari Bakken on 2008-08-13.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- SPACE_REGEXP =
%r{ ( /\*.*?\*/ | # block comments //.*?$\n? | # single-line comments \s* )+ # space }mx
- CONTROL_CHAR =
{ "a" => "\a", "b" => "\b", "n" => "\n", "f" => "\f", "t" => "\t", "r" => "\r", "v" => "\v", }
- BOOLS =
{true => "1", false => "0"}
Instance Method Summary collapse
-
#initialize(string, opts = {}) ⇒ AsciiParser
constructor
string - the plist string to parse.
- #parse ⇒ Object
Constructor Details
#initialize(string, opts = {}) ⇒ AsciiParser
string - the plist string to parse
options hash:
:parse_numbers => true/false : Set this to true if you numeric values (float/ints) as the correct Ruby type
:parse_booleans => true/false : Set this to true if you want "true" and "false" to return the boolean Ruby types
Note: Apple's parsers return strings for all old-style plist types.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vendor/plist.rb', line 57 def initialize(string, opts = {}) string = case string when StringIO string.string when IO string.read else string end @parse_numbers = opts.delete(:parse_numbers) @parse_bools = opts.delete(:parse_booleans) @debug = $VERBOSE == true # ruby -W3 raise ArgumentError, "unknown option #{opts.inspect}" unless opts.empty? super(string) end |
Instance Method Details
#parse ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/vendor/plist.rb', line 76 def parse res = object skip_space error "junk after plist" unless eos? res end |