Class: Apt::Spy2::Country

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

Overview

lookup a country based on code

Instance Method Summary collapse

Constructor Details

#initialize(country_database) ⇒ Country

Returns a new instance of Country.



7
8
9
# File 'lib/apt/spy2/country.rb', line 7

def initialize(country_database)
  @database = country_database
end

Instance Method Details

#to_country_name(code) ⇒ Object



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

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/, '')

    return capitalize!(country) if code == tld
  end

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