class Magiq::Types::UPC

Constants

UPC_MAX
UPC_RNG

Public Instance Methods

cast!() click to toggle source
# File lib/magiq/types.rb, line 99
def cast!
  v = raw.to_s.gsub(UPC_RNG, '').to_i

  if v > 0 && v <= UPC_MAX
    v
  else
    bad! "provided value of #{raw.inspect} is not permitted, it must " \
    "be a valid UPC with a numerical value between zero and #{UPC_MAX}."
  end
end