Class: Alf::Reader::JSON

Inherits:
Alf::Reader show all
Defined in:
lib/alf/reader/json.rb

Overview

Implements Alf::Reader contract for reading JSON input.

Constant Summary

Constants inherited from Alf::Reader

DEFAULT_OPTIONS

Instance Attribute Summary

Attributes inherited from Alf::Reader

#input, #options, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Alf::Reader

by_mime_type, coerce, #initialize, reader, register, #to_s

Methods included from Support::Registry

#listen, #listeners, #register, #registered

Constructor Details

This class inherits a constructor from Alf::Reader

Class Method Details

.mime_typeObject


8
9
10
# File 'lib/alf/reader/json.rb', line 8

def self.mime_type
  "application/json"
end

Instance Method Details

#eachObject


12
13
14
15
16
17
18
19
20
# File 'lib/alf/reader/json.rb', line 12

def each
  return to_enum unless block_given?
  require 'json'
  p = ::JSON.parse(input_text, create_additions: false)
  p = [p] if TupleLike===p
  p.each do |t|
    yield Support.symbolize_keys(t)
  end
end