Class: Analytic::Stat

Inherits:
Object
  • Object
show all
Defined in:
app/models/analytic/stat.rb

Instance Method Summary collapse

Constructor Details

#initialize(current:, prior:, name:) ⇒ Stat

Returns a new instance of Stat.

Parameters:

  • current (Integer)
  • prior (Integer)
  • name (String)


8
9
10
11
12
# File 'app/models/analytic/stat.rb', line 8

def initialize(current:, prior:, name:)
  @current = current
  @prior = prior
  @name = name
end

Instance Method Details

#countInteger

Returns:

  • (Integer)


15
16
17
# File 'app/models/analytic/stat.rb', line 15

def count
  @current
end

#deltaFloat?

e.g. prior = 4 / current = 5 / delta = + 0.25 e.g. prior = 4 / current = 3 / delta = - 0.25

Returns:

  • (Float, nil)


23
24
25
26
27
28
# File 'app/models/analytic/stat.rb', line 23

def delta
  return if @prior.nil?
  return if @prior.zero?

  (@current - @prior).fdiv(@prior)
end