diff options
author | Florian Frank <flori@ping.de> | 2016-09-23 18:37:50 +0300 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2016-09-23 19:38:00 +0300 |
commit | 1d00c8da715eec2e56e2602b001c28f33c32c046 (patch) | |
tree | 635555280cd0cc645d71937efa284124e9c2983c /lib/json/pure/parser.rb | |
parent | 8c7eb9e93916f2d863fc9ead9422427e243a5956 (diff) | |
download | json-1d00c8da715eec2e56e2602b001c28f33c32c046.tar.gz |
Diffstat (limited to 'lib/json/pure/parser.rb')
-rw-r--r-- | lib/json/pure/parser.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/json/pure/parser.rb b/lib/json/pure/parser.rb index b907236..3a6343b 100644 --- a/lib/json/pure/parser.rb +++ b/lib/json/pure/parser.rb @@ -70,6 +70,9 @@ module JSON # option defaults to false. # * *object_class*: Defaults to Hash # * *array_class*: Defaults to Array + # * *decimal_class*: Specifies which class to use instead of the default + # (Float) when parsing decimal numbers. This class must accept a single + # string argument in its constructor. def initialize(source, opts = {}) opts ||= {} source = convert_encoding source @@ -94,6 +97,7 @@ module JSON @create_id = @create_additions ? JSON.create_id : nil @object_class = opts[:object_class] || Hash @array_class = opts[:array_class] || Array + @decimal_class = opts[:decimal_class] @match_string = opts[:match_string] end @@ -193,7 +197,7 @@ module JSON def parse_value case when scan(FLOAT) - Float(self[1]) + @decimal_class && @decimal_class.new(self[1]) || Float(self[1]) when scan(INTEGER) Integer(self[1]) when scan(TRUE) |