class Apt::Spy2::Country
lookup a country based on code
Public Class Methods
new(country_database)
click to toggle source
# File lib/apt/spy2/country.rb, line 7 def initialize(country_database) @database = country_database end
Public Instance Methods
to_country_name(code)
click to toggle source
# 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
Private Instance Methods
capitalize!(str)
click to toggle source
# File lib/apt/spy2/country.rb, line 27 def capitalize!(str) str.split(' ').map(&:capitalize).join(' ') end