Class: Sapristi::AttributeNormalizer

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

Instance Method Summary collapse

Constructor Details

#initialize(key, raw, monitor) ⇒ AttributeNormalizer

Returns a new instance of AttributeNormalizer.



5
6
7
8
9
# File 'lib/sapristi/attribute_normalizer.rb', line 5

def initialize(key, raw, monitor)
  @key = key
  @raw = raw
  @monitor = monitor
end

Instance Method Details

#normalizeObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sapristi/attribute_normalizer.rb', line 11

def normalize
  if percentage?
    apply_percentage
  elsif not_a_percentage_but_includes_symbol?
    raise Error, "key=#{key}, invalid percentage=#{raw}"
  elsif numeric_field?
    raw&.to_i
  else
    raw
  end
end