Module: Xlgrep::InvalidJson

Defined in:
lib/xlgrep/invalid_json.rb

Class Method Summary collapse

Class Method Details

.match(str) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/xlgrep/invalid_json.rb', line 9

def match(str)
  if str =~ /\A[\s\n\r]*(?:\{.*\}|\[.*\])[\s\n\r]*\Z/
    begin
      JSON.parse(str.strip)
    rescue JSON::ParserError => e
      yield(e.message)
    end
  end
end