Class: Igniter::Extensions::Contracts::Differential::Divergence

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/extensions/contracts/differential/divergence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_name:, primary_value:, candidate_value:, kind:) ⇒ Divergence

Returns a new instance of Divergence.



10
11
12
13
14
15
16
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 10

def initialize(output_name:, primary_value:, candidate_value:, kind:)
  @output_name = output_name.to_sym
  @primary_value = primary_value
  @candidate_value = candidate_value
  @kind = kind.to_sym
  freeze
end

Instance Attribute Details

#candidate_valueObject (readonly)

Returns the value of attribute candidate_value.



8
9
10
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 8

def candidate_value
  @candidate_value
end

#kindObject (readonly)

Returns the value of attribute kind.



8
9
10
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 8

def kind
  @kind
end

#output_nameObject (readonly)

Returns the value of attribute output_name.



8
9
10
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 8

def output_name
  @output_name
end

#primary_valueObject (readonly)

Returns the value of attribute primary_value.



8
9
10
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 8

def primary_value
  @primary_value
end

Instance Method Details

#deltaObject



18
19
20
21
22
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 18

def delta
  return nil unless primary_value.is_a?(Numeric) && candidate_value.is_a?(Numeric)

  candidate_value - primary_value
end

#to_hObject



24
25
26
27
28
29
30
31
32
# File 'lib/igniter/extensions/contracts/differential/divergence.rb', line 24

def to_h
  {
    output_name: output_name,
    primary_value: primary_value,
    candidate_value: candidate_value,
    kind: kind,
    delta: delta
  }
end