Module: BetterRecord::MoneyInteger
- Defined in:
- lib/better_record/money_integer.rb
Defined Under Namespace
Modules: TableDefinition Classes: Type
Class Method Summary collapse
Class Method Details
.convert_to_money(value) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/better_record/money_integer.rb', line 6 def self.convert_to_money(value) return StoreAsInt::Money.new(0) unless value if (!value.kind_of?(Numeric)) begin dollars_to_cents = (value.gsub(/\$/, '').presence || 0).to_d * StoreAsInt::Money.base StoreAsInt::Money.new(dollars_to_cents.to_i) rescue StoreAsInt::Money.new end else StoreAsInt::Money.new(value) end end |