Class: Daywalker::Legislator
- Includes:
- HappyMapper
- Defined in:
- lib/daywalker/legislator.rb
Overview
Represents a legislator, either a Senator or Representative.
They have the following attributes:
title
-
The title held by a Legislator, as a Symbol, ether
:senator
or:representative
first_name
-
Legislator’s first name
middle_name
-
Legislator’s middle name
last_name
-
Legislator’s last name
name_suffix
-
Legislator’s suffix (Jr., III, etc)
nickname
-
Preferred nickname of Legislator
party
-
Legislator’s party as a
Sybmol
,:democrat
,:republican
, or:independent
. state
-
two-letter
String
abbreviation of the Legislator’s state. district
-
The district a Legislator represents. For Representatives, this is a
Fixnum
. For Senators, this is aSymbol
, either:junior_seat
or:senior_seat
. in_office
-
true
if the Legislator is currently server, or false if the Legislator is no longer due to defeat/resignation/death/etc. gender
-
Legislator’s gender as a
Symbol
, :male or :female phone
-
Legislator’s Congressional office phone number # FIXME normalize this to phone_number
fax_number
-
Legislator’s Congressional office fax number
website_url
-
URL of the Legislator’s Congressional wesbite as a
String
webform_url
-
URL of the Legislator’s web contact form as a
String
email
-
Legislator’s email address
congress_office
-
Legislator’s Washington, DC Office Address
bioguide_id
-
Legislator’s ID assigned by the COngressional Biographical DIrectory (bioguide.congress.gov) and also used by the Washington Post and NY Times.
votesmart_id
-
Legislator ID assigned by Project Vote Smart (www.votesmart.org).
fec_id
-
Legislator’s ID provided by the Federal Election Commission (fec.gov)
govtrack_id
-
Legislator’s ID provided by Govtrack.us (www.govtrack.us)
crp_id
-
Legislator’s ID provided by Center for Responsive Politics (opensecrets.org)
eventful_id
-
Legislator’s ‘Performer ID’ on eventful.com
congresspedia_url
-
URL of the Legislator’s Congresspedia entry (congresspedia.org)
twitter_id
-
Legislator’s ID on Twitter (twitter.com)
youtube_url
-
URL of the Legislator’s YouTube account (youtube.com) as a
String
Constant Summary collapse
- VALID_ATTRIBUTES =
[:district, :title, :eventful_id, :in_office, :state, :votesmart_id, :official_rss_url, :party, :email, :crp_id, :website_url, :fax_number, :govtrack_id, :first_name, :middle_name, :last_name, :congress_office, :bioguide_id, :webform_url, :youtube_url, :nickname, :phone, :fec_id, :gender, :name_suffix, :twitter_id, :sunlight_old_id, :congresspedia_url]
Class Method Summary collapse
-
.all(conditions) ⇒ Object
Find all legislators matching a Hash of attribute name/values.
-
.all_by_address(address) ⇒ Object
Find all the legislators serving a specific address.
-
.all_by_latitude_and_longitude(latitude, longitude) ⇒ Object
Find all the legislators serving a specific latitude and longitude.
-
.all_by_zip(zip) ⇒ Object
Find all Legislators who serve a particular zip code.
-
.method_missing(method_id, *args, &block) ⇒ Object
:nodoc:.
-
.respond_to?(method_id, include_private = false) ⇒ Boolean
:nodoc:.
-
.unique(conditions) ⇒ Object
Find a unique legislator matching a Hash of attribute name/values.
Class Method Details
.all(conditions) ⇒ Object
Find all legislators matching a Hash of attribute name/values. See VALID_ATTRIBUTES for possible attributes.
Daywalker::Legislator.all(:state => 'NY', :title => :senator)
Dynamic finders based on the attribute names are also possible. This query can be rewritten as:
Daywalker::Legislator.all_by_state_and_title('NY', :senator)
Returns an Array of Legislators.
Gotchas:
-
Results are case insensative (Richard and richard are equivilant)
-
Results are exact (Richard vs Rich)
-
nil attributes will match anything, not legislators without a value for the attribute
-
Passing an Array of values to match, ie
:state => ['NH', 'MA']
is not supported at this time
169 170 171 172 173 174 175 176 |
# File 'lib/daywalker/legislator.rb', line 169 def self.all(conditions) conditions = TypeConverter.normalize_conditions(conditions) query = conditions.merge(:apikey => Daywalker.api_key) response = get('/legislators.getList.xml', :query => query) handle_response(response) end |
.all_by_address(address) ⇒ Object
Find all the legislators serving a specific address. This will include the district’s Represenative, the Senior Senator, and the Junior Senator.
Returns a Hash containing keys :representative, :junior_senator, and :senior_senator, with values corresponding to the appropriate Legislator.
Raises Daywalker::AddressError if the address can’t be geocoded.
201 202 203 204 205 |
# File 'lib/daywalker/legislator.rb', line 201 def self.all_by_address(address) location = Daywalker.geocoder.locate(address) all_by_latitude_and_longitude(location[:latitude], location[:longitude]) end |
.all_by_latitude_and_longitude(latitude, longitude) ⇒ Object
Find all the legislators serving a specific latitude and longitude. This will include the district’s Represenative, the Senior Senator, and the Junior Senator.
Returns a Hash containing keys :representative, :junior_senator, and :senior_senator, with values corresponding to the appropriate Legislator.
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/daywalker/legislator.rb', line 182 def self.all_by_latitude_and_longitude(latitude, longitude) district = District.unique_by_latitude_and_longitude(latitude, longitude) representative = unique_by_state_and_district(district.state, district.number) junior_senator = unique_by_state_and_district(district.state, :junior_seat) senior_senator = unique_by_state_and_district(district.state, :senior_seat) { :representative => representative, :junior_senator => junior_senator, :senior_senator => senior_senator } end |
.all_by_zip(zip) ⇒ Object
Find all Legislators who serve a particular zip code. This would include the Junior and Senior Senators, as well as the Representatives of any Districts in the zip code.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/daywalker/legislator.rb', line 120 def self.all_by_zip(zip) raise ArgumentError, 'missing required parameter zip' if zip.nil? query = { :zip => zip, :apikey => Daywalker.api_key } response = get('/legislators.allForZip.xml', :query => query) handle_response(response) end |
.method_missing(method_id, *args, &block) ⇒ Object
:nodoc:
207 208 209 210 211 212 213 214 215 |
# File 'lib/daywalker/legislator.rb', line 207 def self.method_missing(method_id, *args, &block) # :nodoc: match = DynamicFinderMatch.new(method_id) if match.match? create_finder_method(method_id, match.finder, match.attribute_names) send(method_id, *args, &block) else super end end |
.respond_to?(method_id, include_private = false) ⇒ Boolean
:nodoc:
217 218 219 220 221 222 223 224 |
# File 'lib/daywalker/legislator.rb', line 217 def self.respond_to?(method_id, include_private = false) # :nodoc: match = DynamicFinderMatch.new(method_id) if match.match? true else super end end |
.unique(conditions) ⇒ Object
Find a unique legislator matching a Hash of attribute name/values. See VALID_ATTRIBUTES for possible attributes.
Daywalker::Legislator.unique(:state => 'NY', :district => 4)
Dynamic finders based on the attribute names are also possible. This query can be rewritten as:
Daywalker::Legislator.unique_by_state_and_district('NY', 4)
Returns a Legislator. ArgumentError is raised if more than one result is found.
Gotchas:
-
Results are case insensative (Richard and richard are equivilant)
-
Results are exact (Richard vs Rich are not the same)
145 146 147 148 149 150 151 152 |
# File 'lib/daywalker/legislator.rb', line 145 def self.unique(conditions) conditions = TypeConverter.normalize_conditions(conditions) query = conditions.merge(:apikey => Daywalker.api_key) response = get('/legislators.get.xml', :query => query) handle_response(response).first end |