Class: Grubby::JsonParser

Inherits:
Mechanize::File
  • Object
show all
Defined in:
lib/grubby/json_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil, response = nil, body = nil, code = nil) ⇒ JsonParser

Returns a new instance of JsonParser.



41
42
43
44
# File 'lib/grubby/json_parser.rb', line 41

def initialize(uri = nil, response = nil, body = nil, code = nil)
  @json = body.presence && JSON.parse(body, self.class.json_parse_options)
  super
end

Instance Attribute Details

#jsonHash, Array (readonly)

The parsed JSON data.

Returns:

  • (Hash, Array)


39
40
41
# File 'lib/grubby/json_parser.rb', line 39

def json
  @json
end

Class Method Details

.json_parse_optionsHash

Returns the options to use when parsing JSON. The returned options Hash is not duped and can be modified directly. Any modifications will be applied to all future parsing.

For information about available options, see JSON.parse.

Returns:

  • (Hash)


12
13
14
15
16
17
18
19
20
21
# File 'lib/grubby/json_parser.rb', line 12

def self.json_parse_options
  @json_parse_options ||= {
    max_nesting: false,
    allow_nan: false,
    symbolize_names: false,
    create_additions: false,
    object_class: Hash,
    array_class: Array,
  }
end

.json_parse_options=(options) ⇒ Object

Sets the options to use when parsing JSON. The entire options Hash is replaced, and the new value will be applied to all future parsing. To set options individually, see json_parse_options.

For information about available options, see JSON.parse.

Parameters:

  • options (Hash)


32
33
34
# File 'lib/grubby/json_parser.rb', line 32

def self.json_parse_options=(options)
  @json_parse_options = options
end