Class: TrajectPlus::JsonReader

Inherits:
Object
  • Object
show all
Defined in:
lib/traject_plus/json_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_stream, settings) ⇒ JsonReader

Returns a new instance of JsonReader.

Parameters:

  • input_stream (File)
  • settings (Traject::Indexer::Settings)


8
9
10
11
12
# File 'lib/traject_plus/json_reader.rb', line 8

def initialize(input_stream, settings)
  @settings = Traject::Indexer::Settings.new settings
  @input_stream = input_stream
  @json = JSON.parse(input_stream.read)
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



14
15
16
# File 'lib/traject_plus/json_reader.rb', line 14

def json
  @json
end

Instance Method Details

#each(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/traject_plus/json_reader.rb', line 16

def each(&block)
  return to_enum(:each) unless block_given?

  if json.is_a? Array
    json.each(&block)
  else
    yield json
  end
end