Class: MrCommon::Country

Inherits:
Object
  • Object
show all
Defined in:
app/models/mr_common/country.rb

Overview

Wrapper doing common tasks with the Carmen gem

Class Method Summary collapse

Class Method Details

.all(top = []) ⇒ Array<Array<String, String>>

Returns an array of label-value pairs for building country select options.

Parameters:

  • top (Array<String>) (defaults to: [])

    a list of country codes that should be promoted to the top of the list.

Returns:

  • (Array<Array<String, String>>)

    an array of label-value pairs for building country select options.



11
12
13
14
15
16
17
18
19
# File 'app/models/mr_common/country.rb', line 11

def all(top = [])
  all_countries = label_value_pairs.dup

  top.reverse_each do |alpha2|
    all_countries = promote_one(all_countries, alpha2)
  end

  all_countries
end

.codesArray<String>

Returns two letter country codes in alphabetical order.

Returns:

  • (Array<String>)

    two letter country codes in alphabetical order



22
23
24
# File 'app/models/mr_common/country.rb', line 22

def codes
  Carmen::Country.all.map(&:code).sort
end

.name_for(code) ⇒ String

Returns the name of the country for that code.

Parameters:

  • code (String)

    a two letter country code

Returns:

  • (String)

    the name of the country for that code



33
34
35
# File 'app/models/mr_common/country.rb', line 33

def name_for(code)
  Carmen::Country.alpha_2_coded(code).name
end

.namesArray<String>

Returns country names in alphabetical order.

Returns:

  • (Array<String>)

    country names in alphabetical order



27
28
29
# File 'app/models/mr_common/country.rb', line 27

def names
  Carmen::Country.all.map(&:name).sort
end