class Mobit::Core::Country

Public Class Methods

all_codes() click to toggle source

Return Array of Mobit::Core::Country objects

# File lib/mobit/core/country.rb, line 42
def all_codes
  countries_csv.map do |row|
    Mobit::Core::Country.new(row)
  end
end
new(row = []) click to toggle source

Initialize country from csv file row (Array)

# File lib/mobit/core/country.rb, line 9
def initialize(row = [])
  # "Name", "A2 (ISO)", "A3 (UN)", "Dialing code", "Trunk code"
  @name = row[0] rescue nil
  @iso_a2 = row[1] rescue nil
  @un_a3 = row[2] rescue nil
  @code = row[3] rescue nil
  @trunk_code = row[4] rescue nil
end

Private Class Methods

countries_csv() click to toggle source

Read csv file & create Array

# File lib/mobit/core/country.rb, line 50
def countries_csv
  path = __dir__.sub(/core\Z/i, 'data')
  path += '/country_codes.csv'
  CSV.read(path)[1..-1] rescue []
end

Public Instance Methods

code() click to toggle source
# File lib/mobit/core/country.rb, line 30
def code
  @code
end
iso_a2() click to toggle source
# File lib/mobit/core/country.rb, line 22
def iso_a2
  @iso_a2
end
name() click to toggle source
# File lib/mobit/core/country.rb, line 18
def name
  @name
end
trunk_code() click to toggle source
# File lib/mobit/core/country.rb, line 34
def trunk_code
  @trunk_code
end
un_a3() click to toggle source
# File lib/mobit/core/country.rb, line 26
def un_a3
  @un_a3
end