Sha256: d6fc7b0a8446a5c4563aff87833a3a83e8559b70572d0458df6c1a0dd9b178d2

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

require 'json/pure'

module Tapyrus
  module Ext

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

      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

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tapyrus-0.2.7 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.6 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.5 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.4 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.3 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.2 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.1 lib/tapyrus/ext/json_parser.rb
tapyrus-0.2.0 lib/tapyrus/ext/json_parser.rb