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.



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

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.



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

def alpha2Code
  @alpha2Code
end

#alpha3CodeObject (readonly)

Returns the value of attribute alpha3Code.



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

def alpha3Code
  @alpha3Code
end

#altSpellingsObject (readonly)

Returns the value of attribute altSpellings.



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

def altSpellings
  @altSpellings
end

#areaObject (readonly)

Returns the value of attribute area.



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

def area
  @area
end

#bordersObject (readonly)

Returns the value of attribute borders.



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

def borders
  @borders
end

#callingCodesObject (readonly)

Returns the value of attribute callingCodes.



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

def callingCodes
  @callingCodes
end

#capitalObject (readonly)

Returns the value of attribute capital.



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

def capital
  @capital
end

#currenciesObject (readonly)

Returns the value of attribute currencies.



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

def currencies
  @currencies
end

#demonymObject (readonly)

Returns the value of attribute demonym.



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

def demonym
  @demonym
end

#giniObject (readonly)

Returns the value of attribute gini.



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

def gini
  @gini
end

#languagesObject (readonly)

Returns the value of attribute languages.



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

def languages
  @languages
end

#latlngObject (readonly)

Returns the value of attribute latlng.



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

def latlng
  @latlng
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nativeNameObject (readonly)

Returns the value of attribute nativeName.



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

def nativeName
  @nativeName
end

#populationObject (readonly)

Returns the value of attribute population.



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

def population
  @population
end

#regionObject (readonly)

Returns the value of attribute region.



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

def region
  @region
end

#relevanceObject (readonly)

Returns the value of attribute relevance.



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

def relevance
  @relevance
end

#subregionObject (readonly)

Returns the value of attribute subregion.



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

def subregion
  @subregion
end

#timezonesObject (readonly)

Returns the value of attribute timezones.



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

def timezones
  @timezones
end

#topLevelDomainObject (readonly)

Returns the value of attribute topLevelDomain.



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

def topLevelDomain
  @topLevelDomain
end

#translationsObject (readonly)

Returns the value of attribute translations.



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

def translations
  @translations
end

Class Method Details

.allObject



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

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

.find(name) ⇒ Object



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

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

.find_by_callingcode(callingcode) ⇒ Object



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

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

.find_by_capital(capital) ⇒ Object



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

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

.find_by_currency(currency) ⇒ Object



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

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

.find_by_lang(lang) ⇒ Object



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

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

.find_by_name(name) ⇒ Object



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

def self.find_by_name(name)
  find(name)
end

.find_by_region(region) ⇒ Object



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

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

.find_by_subregion(subregion) ⇒ Object



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

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