lib/money_helper.rb in money_helper-0.0.2 vs lib/money_helper.rb in money_helper-0.0.3

- old
+ new

@@ -2,11 +2,11 @@ require 'active_support/core_ext/object/blank' require 'money' module MoneyHelper - + SYMBOL_ONLY = %w{USD GBP EUR MYR TRY} #don't use ISO code OK_SYMBOLS = %w{ $ £ € ¥ 元 р. L ƒ ৳ P R$ K ₡ D ლ ₵ Q G ₹ Rp ₪ ₩ ₭ R RM ₨ ₮ դր. C$ ₦ TL ₲ ₱ T ฿ T$ m ₴ ₫ ៛ } #ok to include in string @@ -25,13 +25,14 @@ # number_only: (Boolean) optional flag to exclude currency indicators (retains number formatting # specific to currency) def self.money_to_text(amount, currency, number_only = false) return nil unless amount.present? currency = "USD" if currency.blank? - symbol = Money::Currency.new(currency).symbol.strip - include_symbol = !number_only && OK_SYMBOLS.include?(symbol) - (number_only || SYMBOL_ONLY.include?(currency) ? "" : currency + " ") + + symbol = Money::Currency.new(currency).symbol + symbol.strip! if symbol.present? + include_symbol = !number_only && symbol.present? && OK_SYMBOLS.include?(symbol) + (number_only || SYMBOL_ONLY.include?(currency) ? "" : currency + " ") + Money.parse(amount.ceil, currency).format({ no_cents: true, symbol_position: :before, symbol: include_symbol }).delete(' ') @@ -64,7 +65,7 @@ money_to_text(low, currency) else [ money_to_text(low, currency), money_to_text(high, currency, true) ].compact.join(delimiter) end end - + end