Class: Everypolitician::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/everypolitician.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.



84
85
86
87
88
89
# File 'lib/everypolitician.rb', line 84

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.



71
72
73
# File 'lib/everypolitician.rb', line 71

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



70
71
72
# File 'lib/everypolitician.rb', line 70

def name
  @name
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



73
74
75
# File 'lib/everypolitician.rb', line 73

def raw_data
  @raw_data
end

#slugObject (readonly)

Returns the value of attribute slug.



72
73
74
# File 'lib/everypolitician.rb', line 72

def slug
  @slug
end

Class Method Details

.find(query) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/everypolitician.rb', line 75

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



91
92
93
# File 'lib/everypolitician.rb', line 91

def [](key)
  raw_data[key]
end

#legislature(query) ⇒ Object



99
100
101
102
103
104
# File 'lib/everypolitician.rb', line 99

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



95
96
97
# File 'lib/everypolitician.rb', line 95

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