Class: NYTimes::Congress::Legislator
- Includes:
- AttributeTransformation
- Defined in:
- lib/ny-times/congress/legislator.rb
Constant Summary collapse
- ATTRIBUTE_MAP =
{ :date_for => [:date_of_birth], :roles_for => [:roles], :integer_for => [:govtrack_id, :district], :string_for => [:url, :state, :gender, :name, :party, :missed_votes_pct, :votes_with_party_pct] }
- ATTRIBUTES =
ATTRIBUTE_MAP.values.flatten
Constants inherited from Base
Base::API_BASE, Base::API_NAME, Base::API_SERVER, Base::API_VERSION
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Legislator
constructor
A new instance of Legislator.
- #positions ⇒ Object (also: #votes)
Methods included from AttributeTransformation
#date_for, #do_transformation, #empty?, #integer_for, #positions_for, #roles_for, #string_for, #symbol_for, #transform, #votes_for
Methods inherited from Base
api_key, api_key=, build_request_url, copyright, define_lazy_reader_for_attribute_named, invoke
Constructor Details
#initialize(args = {}) ⇒ Legislator
Returns a new instance of Legislator.
25 26 27 28 29 30 31 32 |
# File 'lib/ny-times/congress/legislator.rb', line 25 def initialize(args={}) prepare_arguments(args) @attributes = {} @transformed_arguments.each_pair do |name, value| attributes[name.to_sym] = value end @fully_loaded = false end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/ny-times/congress/legislator.rb', line 18 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'lib/ny-times/congress/legislator.rb', line 18 def id @id end |
Class Method Details
.find(id) ⇒ Object
14 15 16 17 |
# File 'lib/ny-times/congress/legislator.rb', line 14 def self.find(id) response = invoke("members/#{id}.json") new(response['results'].first) end |
Instance Method Details
#positions ⇒ Object Also known as: votes
20 21 22 |
# File 'lib/ny-times/congress/legislator.rb', line 20 def positions @positions ||= fetch_positions end |