Class: SimpleMa
- Inherits:
-
Object
- Object
- SimpleMa
- Defined in:
- lib/rbma/simple_ma.rb
Instance Attribute Summary collapse
-
#empty ⇒ Object
readonly
Returns the value of attribute empty.
-
#lasts ⇒ Object
readonly
Returns the value of attribute lasts.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
Instance Method Summary collapse
- #compute(current:, lasts: nil, empty: nil) ⇒ Object
-
#initialize(n:, empty: "-") ⇒ SimpleMa
constructor
A new instance of SimpleMa.
Constructor Details
#initialize(n:, empty: "-") ⇒ SimpleMa
Returns a new instance of SimpleMa.
6 7 8 9 10 |
# File 'lib/rbma/simple_ma.rb', line 6 def initialize(n:, empty: "-") @n = n @empty = empty @lasts = [] end |
Instance Attribute Details
#empty ⇒ Object (readonly)
Returns the value of attribute empty.
3 4 5 |
# File 'lib/rbma/simple_ma.rb', line 3 def empty @empty end |
#lasts ⇒ Object (readonly)
Returns the value of attribute lasts.
4 5 6 |
# File 'lib/rbma/simple_ma.rb', line 4 def lasts @lasts end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
2 3 4 |
# File 'lib/rbma/simple_ma.rb', line 2 def n @n end |
Instance Method Details
#compute(current:, lasts: nil, empty: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rbma/simple_ma.rb', line 12 def compute(current:, lasts: nil, empty: nil) if lasts.is_a?(Array) @lasts = lasts @empty = @empty ? @empty : empty end @lasts << current if @lasts.size > @n @lasts.last(5) end sum = 0 @lasts.each{ |a| sum +=a } ma = (sum).to_f / @lasts.size if @lasts.size == @n ma else @empty end end |