Class: NmaxCore
- Inherits:
-
Object
- Object
- NmaxCore
- Defined in:
- lib/nmax_core.rb
Overview
frozen_string_literal = true
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(count_limit) ⇒ NmaxCore
constructor
A new instance of NmaxCore.
- #items ⇒ Object
- #propose(number_value) ⇒ Object
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
#max ⇒ Object (readonly)
Returns the value of attribute max.
4 5 6 |
# File 'lib/nmax_core.rb', line 4 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
4 5 6 |
# File 'lib/nmax_core.rb', line 4 def min @min end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/nmax_core.rb', line 4 def size @size end |
Instance Method Details
#items ⇒ Object
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 |