Class: Cats::Core::CommoditySubstitution

Inherits:
ApplicationRecord show all
Defined in:
app/models/cats/core/commodity_substitution.rb

Instance Method Summary collapse

Instance Method Details

#validate_ratioObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/cats/core/commodity_substitution.rb', line 12

def validate_ratio
  return unless ratio

  left, right = ratio.split(":")
  left_correct = begin
    Integer(left).is_a?(Integer)
  rescue StandardError
    false
  end
  right_correct = begin
    Integer(right).is_a?(Integer)
  rescue StandardError
    false
  end

  errors.add(:ratio, "is not in correct format.") unless left_correct && right_correct
end