Class: ApiHammer::Filtration::Json

Inherits:
JSON::Pure::Parser
  • Object
show all
Defined in:
lib/api_hammer/filtration/json.rb

Overview

This class implements the JSON filterer that is used to filter a JSON string

Instance Method Summary collapse

Constructor Details

#initialize(source, opts = {}) ⇒ Json

Creates a new instance for the string source.



11
12
13
14
# File 'lib/api_hammer/filtration/json.rb', line 11

def initialize(source, opts = {})
  super source
  @options = opts
end

Instance Method Details

#filterObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/api_hammer/filtration/json.rb', line 16

def filter
  reset
  obj = ''
  while !eos? && scan_result(obj, IGNORE)
  end
  if eos?
    raise ParserError, "source did not contain any JSON!"
  else
    value = filter_value
    if value == UNPARSED
      raise ParserError, "source did not contain any JSON!"
    else
      obj << value
    end
  end
  obj
end