Class: RustyJson::Parser
- Inherits:
-
Object
- Object
- RustyJson::Parser
- Defined in:
- lib/rusty_json/parser.rb
Overview
Parser is the base class that actually parses JSON into Rust structs
Example: “‘ruby name = ’Test’ json = ‘“world”’ parser = Parser.new(name, json) parser.parse “‘
Instance Method Summary collapse
-
#initialize(name, json) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Object
parse takes the given JSON string and turns it into a string of Rust structs, suitable for use with rustc_serialize.
Constructor Details
#initialize(name, json) ⇒ Parser
Returns a new instance of Parser.
18 19 20 21 |
# File 'lib/rusty_json/parser.rb', line 18 def initialize(name, json) @name = name @json = json end |
Instance Method Details
#parse ⇒ Object
parse takes the given JSON string and turns it into a string of Rust structs, suitable for use with rustc_serialize.
25 26 27 28 |
# File 'lib/rusty_json/parser.rb', line 25 def parse (type, subtype) = parse_object([@name], JSON.parse(@json)) (subtype || type).to_s.gsub(/\n\n$/, "\n") end |