Module: Redmineup::MoneyHelper
- Included in:
- Liquid::Filters::Base
- Defined in:
- lib/redmineup/money_helper.rb
Instance Method Summary collapse
- #all_currencies ⇒ Object
- #collection_for_currencies_select(default_currency = Redmineup::Settings::Money.default_currency, major_currencies = Redmineup::Settings::Money.major_currencies) ⇒ Object
- #deal_currency_icon(currency) ⇒ Object
- #object_price(obj, price_field = :price, options = {}) ⇒ Object
- #price_to_currency(price, currency = Redmineup::Settings::Money.default_currency, options = {}) ⇒ Object
- #prices_collection_by_currency(prices_collection, options = {}) ⇒ Object
Instance Method Details
#all_currencies ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/redmineup/money_helper.rb', line 41 def all_currencies Currency.table.inject([]) do |array, (_, attributes)| array ||= [] array << [attributes[:name].to_s + (attributes[:symbol].blank? ? '' : " (#{attributes[:symbol]})"), attributes[:iso_code]] array end.sort{|x, y| x[0] <=> y[0]} end |
#collection_for_currencies_select(default_currency = Redmineup::Settings::Money.default_currency, major_currencies = Redmineup::Settings::Money.major_currencies) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/redmineup/money_helper.rb', line 31 def collection_for_currencies_select(default_currency = Redmineup::Settings::Money.default_currency, major_currencies = Redmineup::Settings::Money.major_currencies) currencies = [] currencies << default_currency.to_s unless default_currency.blank? currencies |= major_currencies currencies.map do |c| currency = Redmineup::Currency.find(c) ["#{currency.iso_code} (#{currency.symbol})", currency.iso_code] if currency end.compact.uniq end |
#deal_currency_icon(currency) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/redmineup/money_helper.rb', line 18 def deal_currency_icon(currency) case currency.to_s.upcase when 'EUR' 'icon-money-euro' when 'GBP' 'icon-money-pound' when 'JPY' 'icon-money-yen' else 'icon-money-dollar' end end |
#object_price(obj, price_field = :price, options = {}) ⇒ Object
6 7 8 9 |
# File 'lib/redmineup/money_helper.rb', line 6 def object_price(obj, price_field = :price, = {}) .merge!({:symbol => true}) price_to_currency(obj.try(price_field), obj.currency, ).to_s if obj.respond_to?(:currency) end |
#price_to_currency(price, currency = Redmineup::Settings::Money.default_currency, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/redmineup/money_helper.rb', line 49 def price_to_currency(price, currency = Redmineup::Settings::Money.default_currency, = {}) return '' if price.blank? currency = 'USD' unless currency.is_a?(String) = { decimal_mark: Redmineup::Settings::Money.decimal_separator, thousands_separator: Redmineup::Settings::Money.thousands_delimiter }.reject { |_k, v| v.nil? } currency = Redmineup::Currency.find(currency) Redmineup::Currency.format(price.to_f, currency, .merge()) end |
#prices_collection_by_currency(prices_collection, options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/redmineup/money_helper.rb', line 11 def prices_collection_by_currency(prices_collection, = {}) return [] if prices_collection.blank? || prices_collection == 0 prices = prices_collection prices.reject!{|k, v| v.to_i == 0} if [:hide_zeros] prices.collect{|k, v| content_tag(:span, price_to_currency(v, k, :symbol => true), :style => "white-space: nowrap;")}.compact end |