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, mech = nil) ⇒ JsonParser

Returns a new instance of JsonParser.



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

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

Instance Attribute Details

#jsonHash, Array (readonly)

The parsed JSON data.

Returns:

  • (Hash, Array)


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

def json
  @json
end

#mechMechanize?

The Mechanize agent used to make the request.

Returns:

  • (Mechanize, nil)


37
38
39
# File 'lib/grubby/json_parser.rb', line 37

def mech
  @mech
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
# File 'lib/grubby/json_parser.rb', line 12

def self.json_parse_options
  @json_parse_options ||= JSON.load_default_options.merge(create_additions: false)
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)


25
26
27
# File 'lib/grubby/json_parser.rb', line 25

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