Class: Apt::Spy2::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/apt/spy2/country.rb

Instance Method Summary collapse

Constructor Details

#initialize(country_database) ⇒ Country

Returns a new instance of Country.



5
6
7
# File 'lib/apt/spy2/country.rb', line 5

def initialize(country_database)
  @database = country_database
end

Instance Method Details

#to_country_name(code) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apt/spy2/country.rb', line 9

def to_country_name(code)
  code = code.upcase
  return capitalize(code) unless code.length == 2

  File.open(@database).each do |line|
    country, tld = line.split(';', 2)
    tld.gsub!(/\n/, '')

    if code == tld
      return capitalize(country)
    end

  end

  raise "Could not look up: #{code}"
end