Class: RustyJson::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/rusty_json/parser.rb

Constant Summary collapse

BASE_TYPES =
{
  String => 'String',
  Fixnum => 'i64',
  Float => 'f64',
}

Instance Method Summary collapse

Constructor Details

#initialize(name, json) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
# File 'lib/rusty_json/parser.rb', line 12

def initialize(name, json)
  @name = name
  @json = json
  @struct_names = Set.new
  @structs = Set.new
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
# File 'lib/rusty_json/parser.rb', line 19

def parse
  @parsed = JSON.parse(@json)
  if @parsed.is_a? Hash
    struct = parse_hash(@name, @parsed)
  end
  struct.to_s
end