Class: VoteSmart::Office
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#branch_id ⇒ Object
Returns the value of attribute branch_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#level_id ⇒ Object
Returns the value of attribute level_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#office ⇒ Object
Returns the value of attribute office.
-
#short_title ⇒ Object
Returns the value of attribute short_title.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type_id ⇒ Object
Returns the value of attribute type_id.
Class Method Summary collapse
- .all ⇒ Object
- .find_all_by_name(names) ⇒ Object
- .find_all_by_type(type) ⇒ Object
- .find_all_by_type_id(type_id) ⇒ Object
- .find_by_name(name) ⇒ Object
-
.get_branches ⇒ Object
Returns branches of government and their respective IDs.
-
.get_levels ⇒ Object
Returns levels of government and their respective IDs.
-
.get_offices_by_branch_level(branch_id, level_id) ⇒ Object
Returns a list of offices by branch and level of government.
-
.get_offices_by_level(level_id) ⇒ Object
Returns a list of offices by level of government.
-
.get_offices_by_type(type_id) ⇒ Object
Returns a list of offices by office type.
-
.get_offices_by_type_level(type_id, level_id) ⇒ Object
Returns a list of offices by office type and level of government.
-
.get_types ⇒ Object
Gets a list of office types.
Instance Method Summary collapse
- #district_by_state_id_and_number(state_id, number) ⇒ Object
- #districts_by_state_id(state_id) ⇒ Object
- #official_by_state_id(state_id) ⇒ Object
Methods inherited from Common
construct_url, get_json_data, hash2get, #initialize, parallelize!, request, response_child, session, set_attribute_map, #update_attributes
Constructor Details
This class inherits a constructor from VoteSmart::Common
Instance Attribute Details
#branch_id ⇒ Object
Returns the value of attribute branch_id.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def branch_id @branch_id end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def id @id end |
#level_id ⇒ Object
Returns the value of attribute level_id.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def level_id @level_id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def name @name end |
#office ⇒ Object
Returns the value of attribute office.
7 8 9 |
# File 'lib/vote_smart/office.rb', line 7 def office @office end |
#short_title ⇒ Object
Returns the value of attribute short_title.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def short_title @short_title end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def title @title end |
#type_id ⇒ Object
Returns the value of attribute type_id.
5 6 7 |
# File 'lib/vote_smart/office.rb', line 5 def type_id @type_id end |
Class Method Details
.all ⇒ Object
32 33 34 |
# File 'lib/vote_smart/office.rb', line 32 def self.all Type.all.collect { |type| find_all_by_type(type) }.uniq.flatten end |
.find_all_by_name(names) ⇒ Object
48 49 50 51 |
# File 'lib/vote_smart/office.rb', line 48 def self.find_all_by_name names offices = Office.all names.collect {|name| offices.find {|office| office.name == name }} end |
.find_all_by_type(type) ⇒ Object
36 37 38 |
# File 'lib/vote_smart/office.rb', line 36 def self.find_all_by_type type find_all_by_type_id(type.id) end |
.find_all_by_type_id(type_id) ⇒ Object
40 41 42 |
# File 'lib/vote_smart/office.rb', line 40 def self.find_all_by_type_id type_id response_child(get_offices_by_type(type_id), "offices", "office").collect {|attributes| Office.new(attributes)} end |
.find_by_name(name) ⇒ Object
44 45 46 |
# File 'lib/vote_smart/office.rb', line 44 def self.find_by_name name Office.all.collect {|office| office if office.name == name }.compact.first end |
.get_branches ⇒ Object
Returns branches of government and their respective IDs
59 60 61 |
# File 'lib/vote_smart/office.rb', line 59 def self.get_branches request("Office.getBranches") end |
.get_levels ⇒ Object
Returns levels of government and their respective IDs
64 65 66 |
# File 'lib/vote_smart/office.rb', line 64 def self.get_levels request("Office.getLevels") end |
.get_offices_by_branch_level(branch_id, level_id) ⇒ Object
Returns a list of offices by branch and level of government
84 85 86 |
# File 'lib/vote_smart/office.rb', line 84 def self.get_offices_by_branch_level branch_id, level_id request("Office.getOfficesByBranchLevel", "branchId" => branch_id, "levelId" => level_id) end |
.get_offices_by_level(level_id) ⇒ Object
Returns a list of offices by level of government
74 75 76 |
# File 'lib/vote_smart/office.rb', line 74 def self.get_offices_by_level level_id request("Office.getOfficesByLevel", "levelId" => level_id) end |
.get_offices_by_type(type_id) ⇒ Object
Returns a list of offices by office type
69 70 71 |
# File 'lib/vote_smart/office.rb', line 69 def self.get_offices_by_type type_id request("Office.getOfficesByType", "officeTypeId" => type_id) end |
.get_offices_by_type_level(type_id, level_id) ⇒ Object
Returns a list of offices by office type and level of government
79 80 81 |
# File 'lib/vote_smart/office.rb', line 79 def self.get_offices_by_type_level type_id, level_id request("Office.getOfficesByTypeLevel", "levelId" => level_id, "officeTypeId" => type_id) end |
.get_types ⇒ Object
Gets a list of office types
54 55 56 |
# File 'lib/vote_smart/office.rb', line 54 def self.get_types request("Office.getTypes") end |
Instance Method Details
#district_by_state_id_and_number(state_id, number) ⇒ Object
19 20 21 22 23 |
# File 'lib/vote_smart/office.rb', line 19 def district_by_state_id_and_number state_id, number number = number.to_i districts = districts_by_state_id(state_id) districts.find {|district| district.number == number} end |
#districts_by_state_id(state_id) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/vote_smart/office.rb', line 12 def districts_by_state_id state_id @districts_by_state ||= {} districts = District.find_all_by_office_id_and_state_id(self.id, state_id) districts.each { |district| district.office = self } @districts_by_state[state_id] ||= districts end |
#official_by_state_id(state_id) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/vote_smart/office.rb', line 25 def official_by_state_id state_id @official_by_state ||= {} official = Official.find_by_office_id_and_state_id(self.id, state_id) official.office = self if official @official_by_state[state_id] ||= official end |