Class: Everypolitician::Legislature
- Inherits:
-
Object
- Object
- Everypolitician::Legislature
- Defined in:
- lib/everypolitician.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.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #csv_url ⇒ Object
- #directory ⇒ Object
-
#initialize(legislature_data, country) ⇒ Legislature
constructor
A new instance of Legislature.
- #lastmod ⇒ Object
- #legislative_periods ⇒ Object
- #popolo ⇒ Object
Constructor Details
#initialize(legislature_data, country) ⇒ Legislature
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/everypolitician.rb', line 123 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 end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
113 114 115 |
# File 'lib/everypolitician.rb', line 113 def country @country end |
#lastmod_str ⇒ Object (readonly)
Returns the value of attribute lastmod_str.
110 111 112 |
# File 'lib/everypolitician.rb', line 110 def lastmod_str @lastmod_str end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
108 109 110 |
# File 'lib/everypolitician.rb', line 108 def name @name end |
#person_count ⇒ Object (readonly)
Returns the value of attribute person_count.
111 112 113 |
# File 'lib/everypolitician.rb', line 111 def person_count @person_count end |
#popolo_url ⇒ Object (readonly)
Returns the value of attribute popolo_url.
116 117 118 |
# File 'lib/everypolitician.rb', line 116 def popolo_url @popolo_url end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
114 115 116 |
# File 'lib/everypolitician.rb', line 114 def raw_data @raw_data end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
112 113 114 |
# File 'lib/everypolitician.rb', line 112 def sha @sha end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
109 110 111 |
# File 'lib/everypolitician.rb', line 109 def slug @slug end |
#statement_count ⇒ Object (readonly)
Returns the value of attribute statement_count.
115 116 117 |
# File 'lib/everypolitician.rb', line 115 def statement_count @statement_count end |
Class Method Details
.find(country_slug, legislature_slug) ⇒ Object
118 119 120 121 |
# File 'lib/everypolitician.rb', line 118 def self.find(country_slug, legislature_slug) country = Country.find(country_slug) country && country.legislature(legislature_slug) end |
.from_sources_dir(dir) ⇒ Object
153 154 155 156 |
# File 'lib/everypolitician.rb', line 153 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
135 136 137 |
# File 'lib/everypolitician.rb', line 135 def [](key) raw_data[key] end |
#csv_url ⇒ Object
162 163 164 165 |
# File 'lib/everypolitician.rb', line 162 def csv_url @csv_url ||= 'https://cdn.rawgit.com/everypolitician' \ "/everypolitician-data/#{@sha}/#{raw_data[:names]}" end |
#directory ⇒ Object
149 150 151 |
# File 'lib/everypolitician.rb', line 149 def directory @directory = raw_data[:sources_directory].split('/')[1, 2].join('/') end |
#lastmod ⇒ Object
158 159 160 |
# File 'lib/everypolitician.rb', line 158 def lastmod Time.at(lastmod_str.to_i).gmtime end |
#legislative_periods ⇒ Object
143 144 145 146 147 |
# File 'lib/everypolitician.rb', line 143 def legislative_periods @legislative_periods ||= raw_data[:legislative_periods].map do |lp| LegislativePeriod.new(lp, self, country) end end |
#popolo ⇒ Object
139 140 141 |
# File 'lib/everypolitician.rb', line 139 def popolo @popolo ||= Everypolitician::Popolo.parse(open(popolo_url).read) end |