Class: MARC::AlephSequential::Reader
- Inherits:
-
Object
- Object
- MARC::AlephSequential::Reader
- Includes:
- Enumerable, Log
- Defined in:
- lib/marc_alephsequential/reader.rb
Instance Attribute Summary collapse
-
#current_id ⇒ Object
Returns the value of attribute current_id.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #each {|agroup.to_record| ... } ⇒ Object
-
#initialize(filename_or_io, opts = {}) ⇒ Reader
constructor
A new instance of Reader.
Methods included from Log
Constructor Details
#initialize(filename_or_io, opts = {}) ⇒ Reader
Returns a new instance of Reader.
18 19 20 |
# File 'lib/marc_alephsequential/reader.rb', line 18 def initialize(filename_or_io, opts={}) @areader = ASLineReader.new(filename_or_io) end |
Instance Attribute Details
#current_id ⇒ Object
Returns the value of attribute current_id.
16 17 18 |
# File 'lib/marc_alephsequential/reader.rb', line 16 def current_id @current_id end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
15 16 17 |
# File 'lib/marc_alephsequential/reader.rb', line 15 def lines @lines end |
Instance Method Details
#each {|agroup.to_record| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/marc_alephsequential/reader.rb', line 22 def each unless block_given? return enum_for(:each) end agroup = ASLineGroup.new while @areader.has_next? nextid = @areader.peek.id if nextid != @current_id && @areader.peek.valid_id? yield agroup.to_record unless agroup.empty? agroup = ASLineGroup.new @current_id = nextid else agroup.add @areader.next end end # yield whatever is left, unless there's nothing left yield agroup.to_record unless agroup.empty? end |