Class: Everypolitician::Index
- Inherits:
-
Object
- Object
- Everypolitician::Index
- Defined in:
- lib/everypolitician/index.rb
Constant Summary collapse
- DEFAULT_INDEX_URL =
'https://raw.githubusercontent.com/' \ 'everypolitician/everypolitician-data/master/countries.json'.freeze
Instance Attribute Summary collapse
-
#index_url ⇒ Object
readonly
Returns the value of attribute index_url.
Instance Method Summary collapse
- #all_legislatures ⇒ Object
- #countries ⇒ Object
- #country(slug) ⇒ Object
-
#initialize(index_url: DEFAULT_INDEX_URL) ⇒ Index
constructor
A new instance of Index.
Constructor Details
#initialize(index_url: DEFAULT_INDEX_URL) ⇒ Index
Returns a new instance of Index.
11 12 13 |
# File 'lib/everypolitician/index.rb', line 11 def initialize(index_url: DEFAULT_INDEX_URL) @index_url = index_url end |
Instance Attribute Details
#index_url ⇒ Object (readonly)
Returns the value of attribute index_url.
9 10 11 |
# File 'lib/everypolitician/index.rb', line 9 def index_url @index_url end |
Instance Method Details
#all_legislatures ⇒ Object
27 28 29 |
# File 'lib/everypolitician/index.rb', line 27 def all_legislatures @all_legislatures ||= countries.flat_map(&:legislatures) end |
#countries ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/everypolitician/index.rb', line 19 def countries @countries ||= begin JSON.parse(open(index_url).read, symbolize_names: true).map do |c| Country.new(c) end end end |
#country(slug) ⇒ Object
15 16 17 |
# File 'lib/everypolitician/index.rb', line 15 def country(slug) country_index[slug.to_s.downcase] end |