Module: CurrencySelect

Defined in:
lib/currency_select.rb

Overview

Module for creating currency drop-downs.

Constant Summary collapse

CURRENCIES =
Money::Currency.table.inject([]) do |array, (_, currency)|
  array << [
    "#{currency[:name]} - #{currency[:iso_code]}", currency[:iso_code]
  ]
end

Class Method Summary collapse

Class Method Details

.currencies_arrayArray

Returns a two-dimensional array with ISO codes and currency names for option tags.

In the outer array, there will be one element for each currency. Each element looks like this, containing a label and the ISO code:

“Afghan Afghani - AFN”, “AFN”

Returns:

  • (Array)


50
51
52
# File 'lib/currency_select.rb', line 50

def currencies_array
  CURRENCIES
end

.priority_currencies_array(currency_codes = []) ⇒ Array

Returns an array with ISO codes and currency names for currency ISO codes passed as an argument

Example

priority_currencies_array([ "USD", "NOK" ])
# => [
#  ['United States Dollar - USD', 'USD' ],
#  ['Norwegian Kroner - NOK', 'NOK']
# ]

Returns:

  • (Array)


66
67
68
69
70
# File 'lib/currency_select.rb', line 66

def priority_currencies_array(currency_codes = [])
  currency_codes.flat_map do |code|
    currencies_array.select { |currency| currency.last.to_s == code }
  end
end