Class: Everypolitician::Country

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(country_data) ⇒ Country

Returns a new instance of Country.



17
18
19
20
21
22
# File 'lib/everypolitician/country.rb', line 17

def initialize(country_data)
  @name = country_data[:name]
  @code = country_data[:code]
  @slug = country_data[:slug]
  @raw_data = country_data
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/everypolitician/country.rb', line 4

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/everypolitician/country.rb', line 3

def name
  @name
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



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

def raw_data
  @raw_data
end

#slugObject (readonly)

Returns the value of attribute slug.



5
6
7
# File 'lib/everypolitician/country.rb', line 5

def slug
  @slug
end

Class Method Details

.find(query) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/everypolitician/country.rb', line 8

def self.find(query)
  query = { slug: query } if query.is_a?(String)
  country = Everypolitician.countries.find do |c|
    query.all? { |k, v| c[k].to_s.downcase == v.to_s.downcase }
  end
  return if country.nil?
  new(country)
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  raw_data[key]
end

#legislature(query) ⇒ Object



32
33
34
35
36
37
# File 'lib/everypolitician/country.rb', line 32

def legislature(query)
  query = { slug: query } if query.is_a?(String)
  legislatures.find do |l|
    query.all? { |k, v| l.__send__(k).to_s.downcase == v.to_s.downcase }
  end
end

#legislaturesObject



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

def legislatures
  @legislatures ||= @raw_data[:legislatures].map { |l| Legislature.new(l, self) }
end

#lower_houseObject



43
44
45
# File 'lib/everypolitician/country.rb', line 43

def lower_house
  @lower_house ||= most_recent('lower house')
end

#upper_houseObject



39
40
41
# File 'lib/everypolitician/country.rb', line 39

def upper_house
  @upper_house ||= most_recent('upper house')
end