Class: Everypolitician::Legislature
- Inherits:
-
Object
- Object
- Everypolitician::Legislature
- Defined in:
- lib/everypolitician/legislature.rb
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#lastmod_str ⇒ Object
readonly
Returns the value of attribute lastmod_str.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#person_count ⇒ Object
readonly
Returns the value of attribute person_count.
-
#popolo_url ⇒ Object
readonly
Returns the value of attribute popolo_url.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#statement_count ⇒ Object
readonly
Returns the value of attribute statement_count.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #directory ⇒ Object
-
#initialize(legislature_data, country) ⇒ Legislature
constructor
A new instance of Legislature.
- #lastmod ⇒ Object
- #latest_term ⇒ Object
- #legislative_periods ⇒ Object
- #names_url ⇒ Object
- #popolo ⇒ Object
Constructor Details
#initialize(legislature_data, country) ⇒ Legislature
Returns a new instance of Legislature.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/everypolitician/legislature.rb', line 22 def initialize(legislature_data, country) @name = legislature_data[:name] @slug = legislature_data[:slug] @lastmod_str = legislature_data[:lastmod] @person_count = legislature_data[:person_count] @sha = legislature_data[:sha] @statement_count = legislature_data[:statement_count] @popolo_url = legislature_data[:popolo_url] @raw_data = legislature_data @country = country @type = legislature_data[:type] end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
11 12 13 |
# File 'lib/everypolitician/legislature.rb', line 11 def country @country end |
#lastmod_str ⇒ Object (readonly)
Returns the value of attribute lastmod_str.
8 9 10 |
# File 'lib/everypolitician/legislature.rb', line 8 def lastmod_str @lastmod_str end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/everypolitician/legislature.rb', line 6 def name @name end |
#person_count ⇒ Object (readonly)
Returns the value of attribute person_count.
9 10 11 |
# File 'lib/everypolitician/legislature.rb', line 9 def person_count @person_count end |
#popolo_url ⇒ Object (readonly)
Returns the value of attribute popolo_url.
14 15 16 |
# File 'lib/everypolitician/legislature.rb', line 14 def popolo_url @popolo_url end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
12 13 14 |
# File 'lib/everypolitician/legislature.rb', line 12 def raw_data @raw_data end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
10 11 12 |
# File 'lib/everypolitician/legislature.rb', line 10 def sha @sha end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
7 8 9 |
# File 'lib/everypolitician/legislature.rb', line 7 def slug @slug end |
#statement_count ⇒ Object (readonly)
Returns the value of attribute statement_count.
13 14 15 |
# File 'lib/everypolitician/legislature.rb', line 13 def statement_count @statement_count end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/everypolitician/legislature.rb', line 15 def type @type end |
Class Method Details
.find(country_slug, legislature_slug) ⇒ Object
17 18 19 20 |
# File 'lib/everypolitician/legislature.rb', line 17 def self.find(country_slug, legislature_slug) country = Country.find(country_slug) country && country.legislature(legislature_slug) end |
.from_sources_dir(dir) ⇒ Object
57 58 59 60 |
# File 'lib/everypolitician/legislature.rb', line 57 def self.from_sources_dir(dir) @index_by_sources ||= EveryPolitician.countries.map(&:legislatures).flatten.group_by(&:directory) @index_by_sources[dir][0] end |
Instance Method Details
#[](key) ⇒ Object
35 36 37 |
# File 'lib/everypolitician/legislature.rb', line 35 def [](key) raw_data[key] end |
#directory ⇒ Object
49 50 51 |
# File 'lib/everypolitician/legislature.rb', line 49 def directory @directory = raw_data[:sources_directory].split('/')[1, 2].join('/') end |
#lastmod ⇒ Object
62 63 64 |
# File 'lib/everypolitician/legislature.rb', line 62 def lastmod Time.at(lastmod_str.to_i).gmtime end |
#latest_term ⇒ Object
53 54 55 |
# File 'lib/everypolitician/legislature.rb', line 53 def latest_term @latest_term ||= popolo.latest_term end |
#legislative_periods ⇒ Object
43 44 45 46 47 |
# File 'lib/everypolitician/legislature.rb', line 43 def legislative_periods @legislative_periods ||= raw_data[:legislative_periods].map do |lp| LegislativePeriod.new(lp, self, country) end end |
#names_url ⇒ Object
66 67 68 69 |
# File 'lib/everypolitician/legislature.rb', line 66 def names_url 'https://cdn.rawgit.com/everypolitician/everypolitician-data/%s/%s' % [sha, raw_data[:names]] end |
#popolo ⇒ Object
39 40 41 |
# File 'lib/everypolitician/legislature.rb', line 39 def popolo @popolo ||= Everypolitician::Popolo.parse(open(popolo_url).read) end |