Class: Arknmax::Reader

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

Overview

:nodoc:

Constant Summary collapse

DIGIT =
/\d/
DIGIT_LINE =
/\d+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size_limit, io: STDIN, max_digits_line: 1000) ⇒ Reader

Returns a new instance of Reader.



12
13
14
15
16
17
# File 'lib/arknmax/reader.rb', line 12

def initialize(size_limit, io: STDIN, max_digits_line: 1000)
  @size_limit = size_limit
  @io = io
  @max_digits_line = max_digits_line
  @container = Arknmax::Heap.new(size_limit)
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



10
11
12
# File 'lib/arknmax/reader.rb', line 10

def container
  @container
end

#ioObject (readonly)

Returns the value of attribute io.



9
10
11
# File 'lib/arknmax/reader.rb', line 9

def io
  @io
end

#max_digits_lineObject (readonly)

Returns the value of attribute max_digits_line.



9
10
11
# File 'lib/arknmax/reader.rb', line 9

def max_digits_line
  @max_digits_line
end

#size_limitObject (readonly)

Returns the value of attribute size_limit.



9
10
11
# File 'lib/arknmax/reader.rb', line 9

def size_limit
  @size_limit
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
# File 'lib/arknmax/reader.rb', line 19

def perform
  while (line = io.read(max_digits_line))
    finish_digits_line!(line) if end_with_num_char?(line)

    line.scan(DIGIT_LINE) { |n| container << n.to_i }
  end

  container
end