Module: ShopifyCountries

Defined in:
lib/shopify_countries.rb,
lib/shopify_countries/version.rb

Constant Summary collapse

COUNTRY_DATA_FILE_NAME =
'countries_data'
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.countriesObject Also known as: all

List of countries



28
29
30
31
32
33
34
# File 'lib/shopify_countries.rb', line 28

def countries
  @countries ||= JSON.parse(
    File.read(File.expand_path(
                "shopify_countries/#{COUNTRY_DATA_FILE_NAME}.json", __dir__
              ))
  )
end

.find_by_code(code) ⇒ Object

FInd country by code



18
19
20
# File 'lib/shopify_countries.rb', line 18

def find_by_code(code)
  countries.find { |country| country['code'] == code }
end

.find_by_name(name) ⇒ Object

Find country by name



13
14
15
# File 'lib/shopify_countries.rb', line 13

def find_by_name(name)
  countries.find { |country| country['name'] == name }
end

.option_list(label_attribute = 'name') ⇒ Object

Option list for HTML select



23
24
25
# File 'lib/shopify_countries.rb', line 23

def option_list(label_attribute = 'name')
  countries.map { |country| [country[label_attribute], country['code']] }
end