Sha256: f84996bc98b34fcc30b57e0616f6a9136f61f479c9d50eff8cbf39f67d62b88f

Contents?: true

Size: 916 Bytes

Versions: 13

Compression:

Stored size: 916 Bytes

Contents

class Gman < NaughtyOrNice

  # Map last part of TLD to alpha2 country code
  ALPHA2_MAP = {
    :ac     => 'sh',
    :uk     => 'gb',
    :su     => 'ru',
    :tp     => 'tl',
    :yu     => 'rs',
    :gov    => "us",
    :mil    => "us",
    :org    => "us",
    :com    => "us",
    :net    => "us",
    :edu    => "us",
    :travel => "us",
    :info   => "us"
  }

  # Returns the two character alpha county code represented by the domain
  #
  # e.g., United States = US, United Kingdom = GB
  def alpha2
    alpha2 = domain_parts.tld.split('.').last
    if ALPHA2_MAP[alpha2.to_sym]
      ALPHA2_MAP[alpha2.to_sym]
    else
      alpha2
    end
  end

  # Returns the ISO Country represented by the domain
  #
  # Example Usage:
  # Gman.new("foo.gov").country.name     => "United States"
  # Gman.new("foo.gov").country.currency => "USD"
  def country
    @country ||= IsoCountryCodes.find(alpha2)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gman-4.4.3 lib/gman/country_codes.rb
gman-4.4.2 lib/gman/country_codes.rb
gman-4.4.1 lib/gman/country_codes.rb
gman-4.4.0 lib/gman/country_codes.rb
gman-4.3.1 lib/gman/country_codes.rb
gman-4.3.0 lib/gman/country_codes.rb
gman-4.2.1 lib/gman/country_codes.rb
gman-4.2.0 lib/gman/country_codes.rb
gman-4.1.4 lib/gman/country_codes.rb
gman-4.1.3 lib/gman/country_codes.rb
gman-4.1.2 lib/gman/country_codes.rb
gman-4.1.1 lib/gman/country_codes.rb
gman-4.1.0 lib/gman/country_codes.rb