Class: Restcountry::Country

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Country

Returns a new instance of Country.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/restcountry/country.rb', line 31

def initialize(attributes)
  @name = attributes['name']
  @capital = attributes['capital']
  @altSpellings = attributes['altSpellings']
  @relevance = attributes['relevance']
  @region = attributes['region']
  @subregion = attributes['subregion']
  @translations = attributes['translations']
  @population = attributes['population']
  @latlng = attributes['latlng']
  @demonym = attributes['demonym']
  @area = attributes['area']
  @gini = attributes['gini']
  @timezones = attributes['timezones']
  @borders = attributes['borders']
  @nativeName = attributes['nativeName']
  @callingCodes = attributes['callingCodes']
  @topLevelDomain = attributes['topLevelDomain']
  @alpha2Code = attributes['alpha2Code']
  @alpha3Code = attributes['alpha3Code']
  @currencies = attributes['currencies']
  @languages = attributes['languages']
end

Instance Attribute Details

#alpha2CodeObject (readonly)

Returns the value of attribute alpha2Code.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def alpha2Code
  @alpha2Code
end

#alpha3CodeObject (readonly)

Returns the value of attribute alpha3Code.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def alpha3Code
  @alpha3Code
end

#altSpellingsObject (readonly)

Returns the value of attribute altSpellings.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def altSpellings
  @altSpellings
end

#areaObject (readonly)

Returns the value of attribute area.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def area
  @area
end

#bordersObject (readonly)

Returns the value of attribute borders.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def borders
  @borders
end

#callingCodesObject (readonly)

Returns the value of attribute callingCodes.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def callingCodes
  @callingCodes
end

#capitalObject (readonly)

Returns the value of attribute capital.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def capital
  @capital
end

#currenciesObject (readonly)

Returns the value of attribute currencies.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def currencies
  @currencies
end

#demonymObject (readonly)

Returns the value of attribute demonym.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def demonym
  @demonym
end

#giniObject (readonly)

Returns the value of attribute gini.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def gini
  @gini
end

#languagesObject (readonly)

Returns the value of attribute languages.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def languages
  @languages
end

#latlngObject (readonly)

Returns the value of attribute latlng.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def latlng
  @latlng
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def name
  @name
end

#nativeNameObject (readonly)

Returns the value of attribute nativeName.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def nativeName
  @nativeName
end

#populationObject (readonly)

Returns the value of attribute population.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def population
  @population
end

#regionObject (readonly)

Returns the value of attribute region.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def region
  @region
end

#relevanceObject (readonly)

Returns the value of attribute relevance.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def relevance
  @relevance
end

#subregionObject (readonly)

Returns the value of attribute subregion.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def subregion
  @subregion
end

#timezonesObject (readonly)

Returns the value of attribute timezones.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def timezones
  @timezones
end

#topLevelDomainObject (readonly)

Returns the value of attribute topLevelDomain.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def topLevelDomain
  @topLevelDomain
end

#translationsObject (readonly)

Returns the value of attribute translations.



9
10
11
# File 'lib/restcountry/country.rb', line 9

def translations
  @translations
end

Class Method Details

.allObject



99
100
101
102
# File 'lib/restcountry/country.rb', line 99

def self.all
  countries = get_response('all')
  countries.map { |attributes| new(attributes) }
end

.find(name, fulltext = false) ⇒ Object



55
56
57
58
# File 'lib/restcountry/country.rb', line 55

def self.find(name, fulltext = false)
  countries = get_response('name', name + "?fullText=#{fulltext}")
  new(countries.first) unless countries.empty?
end

.find_by_callingcode(callingcode) ⇒ Object



89
90
91
92
# File 'lib/restcountry/country.rb', line 89

def self.find_by_callingcode(callingcode)
  countries = get_response('callingcode', callingcode)
  countries.map { |attributes| new(attributes) }
end

.find_by_capital(capital) ⇒ Object



69
70
71
72
# File 'lib/restcountry/country.rb', line 69

def self.find_by_capital(capital)
  countries = get_response('capital', capital)
  new(countries.first) unless countries.empty?
end

.find_by_countrycode(countrycode) ⇒ Object



94
95
96
97
# File 'lib/restcountry/country.rb', line 94

def self.find_by_countrycode(countrycode)
  countries = get_response(nil, "alpha?codes=#{countrycode}")
  countries.map { |attributes| new(attributes) }
end

.find_by_currency(currency) ⇒ Object



64
65
66
67
# File 'lib/restcountry/country.rb', line 64

def self.find_by_currency(currency)
  countries = get_response('currency', currency)
  countries.map { |attributes| new(attributes) }
end

.find_by_lang(lang) ⇒ Object



84
85
86
87
# File 'lib/restcountry/country.rb', line 84

def self.find_by_lang(lang)
  countries = get_response('lang', lang)
  countries.map { |attributes| new(attributes) }
end

.find_by_name(name, fulltext = false) ⇒ Object



60
61
62
# File 'lib/restcountry/country.rb', line 60

def self.find_by_name(name, fulltext = false)
  find(name, fulltext)
end

.find_by_region(region) ⇒ Object



74
75
76
77
# File 'lib/restcountry/country.rb', line 74

def self.find_by_region(region)
  countries = get_response('region', region)
  countries.map { |attributes| new(attributes) }
end

.find_by_subregion(subregion) ⇒ Object



79
80
81
82
# File 'lib/restcountry/country.rb', line 79

def self.find_by_subregion(subregion)
  countries = get_response('subregion', subregion)
  countries.map { |attributes| new(attributes) }
end