module MoneyRails::ActionViewExtension

Public Instance Methods

currency_symbol(currency = Money.default_currency) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 3
def currency_symbol(currency = Money.default_currency)
  content_tag(:span, Money::Currency.find(currency).symbol, class: "currency_symbol")
end
humanized_money(value, options={}) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 7
def humanized_money(value, options={})
  if !options || !options.is_a?(Hash)
    warn "humanized_money now takes a hash of formatting options, please specify { symbol: true }"
    options = { symbol: options }
  end

  options = {
    no_cents_if_whole: MoneyRails::Configuration.no_cents_if_whole.nil? ? true : MoneyRails::Configuration.no_cents_if_whole,
    symbol: false
  }.merge(options)
  options.delete(:symbol) if options[:disambiguate]

  if value.is_a?(Money)
    value.format(options)
  elsif value.respond_to?(:to_money)
    value.to_money.format(options)
  else
    ""
  end
end
humanized_money_with_symbol(value, options={}) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 28
def humanized_money_with_symbol(value, options={})
  humanized_money(value, options.merge(symbol: true))
end
money_only_cents(value) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 51
def money_only_cents(value)
  return '00' unless value.respond_to?(:to_money)

  value = value.to_money

  format "%0#{value.currency.exponent}d", (value % value.currency.subunit_to_unit).cents
end
money_without_cents(value, options={}) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 32
def money_without_cents(value, options={})
  if !options || !options.is_a?(Hash)
    warn "money_without_cents now takes a hash of formatting options, please specify { symbol: true }"
    options = { symbol: options }
  end

  options = {
    no_cents: true,
    no_cents_if_whole: false,
    symbol: false
  }.merge(options)

  humanized_money(value, options)
end
money_without_cents_and_with_symbol(value) click to toggle source
# File lib/money-rails/helpers/action_view_extension.rb, line 47
def money_without_cents_and_with_symbol(value)
  money_without_cents(value, symbol: true)
end