Class: Everypolitician::Index
- Inherits:
-
Object
- Object
- Everypolitician::Index
- Defined in:
- lib/everypolitician.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
- #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.
46 47 48 |
# File 'lib/everypolitician.rb', line 46 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.
44 45 46 |
# File 'lib/everypolitician.rb', line 44 def index_url @index_url end |
Instance Method Details
#countries ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/everypolitician.rb', line 54 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
50 51 52 |
# File 'lib/everypolitician.rb', line 50 def country(slug) country_index[slug.to_s.downcase] end |