Class: Bitcoin::Ext::JsonParser

Inherits:
JSON::Pure::Parser
  • Object
show all
Defined in:
lib/bitcoin/ext/json_parser.rb

Overview

Extension of JSON::Pure::Parser. This class convert Float value to String value.

Instance Method Summary collapse

Instance Method Details

#parse_valueObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bitcoin/ext/json_parser.rb', line 9

def parse_value
  case
  when scan(FLOAT)
    self[1].to_s
  when scan(INTEGER)
    Integer(self[1])
  when scan(TRUE)
    true
  when scan(FALSE)
    false
  when scan(NULL)
    nil
  when !UNPARSED.equal?(string = parse_string)
    string
  when scan(ARRAY_OPEN)
    @current_nesting += 1
    ary = parse_array
    @current_nesting -= 1
    ary
  when scan(OBJECT_OPEN)
    @current_nesting += 1
    obj = parse_object
    @current_nesting -= 1
    obj
  when @allow_nan && scan(NAN)
    NaN
  when @allow_nan && scan(INFINITY)
    Infinity
  when @allow_nan && scan(MINUS_INFINITY)
    MinusInfinity
  else
    UNPARSED
  end
end