Class: Magiq::Types::UPC
Constant Summary collapse
- UPC_RNG =
/[^0-9]/
- UPC_MAX =
9999999999999
Instance Attribute Summary
Attributes inherited from Type
Instance Method Summary collapse
Methods inherited from Type
Constructor Details
This class inherits a constructor from Magiq::Types::Type
Instance Method Details
#cast! ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# 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 |