Class: EPlat::Utils::Money
- Inherits:
-
Object
- Object
- EPlat::Utils::Money
- Includes:
- ActionView::Helpers::NumberHelper, ActiveModel::Model
- Defined in:
- lib/e_plat/utils/money.rb
Class Method Summary collapse
- .coinage_to_poundage_str(number) ⇒ Object
- .money_string_total(money_string, quantity) ⇒ Object
- .percent_discount_int(original_price, discounted_price) ⇒ Object
- .string_to_coinage_int(money_string) ⇒ Object
Class Method Details
.coinage_to_poundage_str(number) ⇒ Object
20 21 22 |
# File 'lib/e_plat/utils/money.rb', line 20 def self.coinage_to_poundage_str(number) ::ApplicationController.helpers.number_with_precision( number.to_f/100, precision: 2).to_s end |
.money_string_total(money_string, quantity) ⇒ Object
24 25 26 27 |
# File 'lib/e_plat/utils/money.rb', line 24 def self.money_string_total(money_string, quantity) coinage = string_to_coinage_int(money_string) coinage_to_poundage_str(coinage*quantity.to_i) end |
.percent_discount_int(original_price, discounted_price) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/e_plat/utils/money.rb', line 12 def self.percent_discount_int(original_price, discounted_price) return 0 if original_price.to_f.zero? discount_amount = original_price.to_f - discounted_price.to_f discount_percentage = (discount_amount / original_price.to_f)*100 discount_percentage.round end |
.string_to_coinage_int(money_string) ⇒ Object
7 8 9 10 |
# File 'lib/e_plat/utils/money.rb', line 7 def self.string_to_coinage_int(money_string) decimals_removed = ::ApplicationController.helpers.number_with_precision(money_string, precision: 2) (decimals_removed.to_f*100).to_i end |