Class: FormatParser::JSONParser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/json_parser.rb

Defined Under Namespace

Classes: Validator

Constant Summary collapse

JSON_MIME_TYPE =
'application/json'

Constants included from IOUtils

IOUtils::INTEGER_DIRECTIVES

Instance Method Summary collapse

Methods included from IOUtils

#read_bytes, #read_fixed_point, #read_int, #safe_read, #safe_skip, #skip_bytes

Instance Method Details

#call(io) ⇒ Object



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

def call(io)
  io = FormatParser::IOConstraint.new(io)
  validator = Validator.new(io)

  validator.validate

  FormatParser::Text.new(
    format: :json,
    content_type: JSON_MIME_TYPE,
  )
rescue Validator::JSONParserError
  nil
end

#likely_match?(filename) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/parsers/json_parser.rb', line 7

def likely_match?(filename)
  filename =~ /\.json$/i
end