Class: BibliographicalImporter::JSON::Reader

Inherits:
Object
  • Object
show all
Includes:
AbstractReader, Enumerable
Defined in:
lib/bibliographical_importer/json.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_bib) ⇒ Reader

Returns a new instance of Reader



149
150
151
152
# File 'lib/bibliographical_importer/json.rb', line 149

def initialize(json_bib)
  @jb=json_bib
  parse_records
end

Instance Attribute Details

#jbObject (readonly)

Returns the value of attribute jb



140
141
142
# File 'lib/bibliographical_importer/json.rb', line 140

def jb
  @jb
end

#recordsObject (readonly)

Returns the value of attribute records



141
142
143
# File 'lib/bibliographical_importer/json.rb', line 141

def records
  @records
end

Class Method Details

.open(filename) ⇒ Object



154
155
156
157
# File 'lib/bibliographical_importer/json.rb', line 154

def self.open(filename)
  b=::JSON.parse(File.read(filename))
  Reader.new(b)
end

.parse(string) ⇒ Object



159
160
161
162
# File 'lib/bibliographical_importer/json.rb', line 159

def self.parse(string)
  b=::JSON.parse(string)
  Reader.new(b)
end

Instance Method Details

#[](x) ⇒ Object



143
144
145
# File 'lib/bibliographical_importer/json.rb', line 143

def [](x)
  @records[x]
end

#each(&block) ⇒ Object



146
147
148
# File 'lib/bibliographical_importer/json.rb', line 146

def each(&block)
  @records.each(&block)
end

#parse_recordsObject



164
165
166
# File 'lib/bibliographical_importer/json.rb', line 164

def parse_records
  @records=@jb.map {|r| BibliographicalImporter::JSON::Record.create(r)}
end