Class: Nmax::Integer

Inherits:
Base
  • Object
show all
Defined in:
lib/nmax/integer.rb

Constant Summary collapse

MAX_LENGTH =
1000

Instance Attribute Summary

Attributes inherited from Base

#count

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Nmax::Base

Instance Method Details

#perform(io) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/nmax/integer.rb', line 7

def perform(io)
  super do
    io.each_line&.reduce([]) do |acc, line|
      acc += line.scan(Regexp.new("\\d{1,#{MAX_LENGTH}}"))
                 .map(&:to_i)
                 .sort
                 .last(count)
      acc.sort.last(count)
    end
  end
end