Class: OfflineSort::Chunk::InputOutput::Base
- Inherits:
-
Object
- Object
- OfflineSort::Chunk::InputOutput::Base
show all
- Defined in:
- lib/offline_sort/chunk/input_output/base.rb
Constant Summary
collapse
- MethodNotImplementedError =
Class.new(StandardError)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(io) ⇒ Base
Returns a new instance of Base.
12
13
14
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 12
def initialize(io)
@io = io
end
|
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
10
11
12
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 10
def io
@io
end
|
Instance Method Details
#close ⇒ Object
37
38
39
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 37
def close
io.close
end
|
#each ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 41
def each
Enumerator.new do |yielder|
loop do
yielder.yield(read_entry)
rescue EOFError
break
end
end
end
|
#flush ⇒ Object
28
29
30
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 28
def flush
io.flush
end
|
#read_entry ⇒ Object
16
17
18
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 16
def read_entry
raise MethodNotImplementedError.new("#{__method__} must be overridden by #{self.class}")
end
|
#rewind ⇒ Object
32
33
34
35
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 32
def rewind
flush
io.rewind
end
|
#write_entries(entries) ⇒ Object
24
25
26
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 24
def write_entries(entries)
entries.each { |entry| write_entry(entry) }
end
|
#write_entry(_entry) ⇒ Object
20
21
22
|
# File 'lib/offline_sort/chunk/input_output/base.rb', line 20
def write_entry(_entry)
raise MethodNotImplementedError.new("#{__method__} must be overridden by #{self.class}")
end
|