Class: Bismas::Reader

Inherits:
Base
  • Object
show all
Defined in:
lib/bismas/reader.rb

Constant Summary collapse

DEFAULT_IO =
$stdin

Instance Attribute Summary collapse

Attributes inherited from Base

#auto_id, #io, #key

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Bismas::Base

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



48
49
50
# File 'lib/bismas/reader.rb', line 48

def records
  @records
end

Class Method Details

.parse(*args, &block) ⇒ Object



37
38
39
40
# File 'lib/bismas/reader.rb', line 37

def parse(*args, &block)
  reader = new(args.extract_options!).parse(*args, &block)
  block ? reader : reader.records
end

.parse_file(*args, &block) ⇒ Object



42
43
44
# File 'lib/bismas/reader.rb', line 42

def parse_file(*args, &block)
  file_method(:parse, 'rb', *args, &block)
end

Instance Method Details

#parse(io = io(), &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bismas/reader.rb', line 55

def parse(io = io(), &block)
  unless block
    records, block = @records, amend_block { |id, record|
      records[id] = record
    }
  end

  Parser.parse(io, @options) { |record|
    block[key ? record[key].join : auto_id.call, record] }

  self
end

#resetObject



50
51
52
53
# File 'lib/bismas/reader.rb', line 50

def reset
  super
  @records = {}
end