Class: NmaxCore

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

Overview

frozen_string_literal = true

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count_limit) ⇒ NmaxCore

Returns a new instance of NmaxCore.



6
7
8
9
10
11
12
# File 'lib/nmax_core.rb', line 6

def initialize(count_limit)
  @buffer = []
  @min = nil
  @max = 0
  @size = 0
  @count_limit = count_limit
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



4
5
6
# File 'lib/nmax_core.rb', line 4

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



4
5
6
# File 'lib/nmax_core.rb', line 4

def min
  @min
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/nmax_core.rb', line 4

def size
  @size
end

Instance Method Details

#itemsObject



24
25
26
# File 'lib/nmax_core.rb', line 24

def items
  @buffer
end

#propose(number_value) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/nmax_core.rb', line 14

def propose(number_value)
  sorted_insert(number_value)
  @min = number_value if @min.nil?

  return if @size <= @count_limit

  @buffer.shift
  @size -= 1
end