Class: Regrapher::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/regrapher/parser.rb

Constant Summary collapse

LINE_REGEX =
/\[regrapher\]\[(\d+)\](.+)$/

Instance Method Summary collapse

Instance Method Details

#parse(line) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/regrapher/parser.rb', line 5

def parse(line)
  _, length, rest = line.match(LINE_REGEX).to_a
  if length && rest && rest.length >= 2 && (length=length.to_i) <= rest.length
    begin
      JSON.parse rest[0, length], symbolize_names: true
    rescue JSON::ParserError
      # mute exception
    end
  end
end