Class: NaturalEarth::Country

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

Overview

A NaturalEarth country

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Country

Returns a new instance of Country.



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

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/natural_earth/country.rb', line 6

def data
  @data
end

Instance Method Details

#continentObject



20
21
22
# File 'lib/natural_earth/country.rb', line 20

def continent
  data['continent']
end

#geometryObject



32
33
34
# File 'lib/natural_earth/country.rb', line 32

def geometry
  Geometries.country(iso3166)
end

#iso3166(format: 'alpha-2') ⇒ Object



12
13
14
# File 'lib/natural_earth/country.rb', line 12

def iso3166(format: 'alpha-2')
  data.dig('iso-3166-1', format)
end

#nameObject



16
17
18
# File 'lib/natural_earth/country.rb', line 16

def name
  data['name']
end

#regionObject



24
25
26
# File 'lib/natural_earth/country.rb', line 24

def region
  data['region']
end

#subdivisionsObject



28
29
30
# File 'lib/natural_earth/country.rb', line 28

def subdivisions
  data['subdivisions'].each_with_object({}) { |iso3166, subs| subs[iso3166] = Subdivisions[iso3166] }
end