Class: Positions
- Inherits:
-
Object
- Object
- Positions
- Defined in:
- lib/congress_person.rb
Constant Summary collapse
- OPENS_POS_MAP =
Maps specific set of CongressPerson attributes to OpenSecrets APIs. Mapping is structured “name of attr in CongressPerson object” => “name of hash key in result returned from API call”
{ "title" => "title", "organization" => "organization" }
Instance Attribute Summary collapse
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(init_hash) ⇒ Positions
constructor
Given a hash of Positions values from the OpenSecrets API, populate the corresponding instance variables in this instance.
-
#pretty_print(pp) ⇒ Object
Pretty print this instance.
Constructor Details
#initialize(init_hash) ⇒ Positions
Given a hash of Positions values from the OpenSecrets API, populate the corresponding instance variables in this instance.
184 185 186 187 188 189 |
# File 'lib/congress_person.rb', line 184 def initialize(init_hash) OPENS_POS_MAP.each do |name, attribute| val = init_hash[attribute] instance_variable_set("@#{name}", val) end end |
Instance Attribute Details
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
173 174 175 |
# File 'lib/congress_person.rb', line 173 def organization @organization end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
173 174 175 |
# File 'lib/congress_person.rb', line 173 def title @title end |
Instance Method Details
#pretty_print(pp) ⇒ Object
Pretty print this instance. This method is called behind the scenes when a Position is encountered during a PP traversal of objects.
193 194 195 |
# File 'lib/congress_person.rb', line 193 def pretty_print(pp) pp.text("position #{title} at #{organization}") end |