Class: VoteSmart::District

Inherits:
Common
  • Object
show all
Defined in:
lib/vote_smart/district.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/vote_smart/district.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/vote_smart/district.rb', line 5

def name
  @name
end

#officeObject

Returns the value of attribute office.



7
8
9
# File 'lib/vote_smart/district.rb', line 7

def office
  @office
end

#office_idObject

Returns the value of attribute office_id.



5
6
7
# File 'lib/vote_smart/district.rb', line 5

def office_id
  @office_id
end

#state_idObject

Returns the value of attribute state_id.



5
6
7
# File 'lib/vote_smart/district.rb', line 5

def state_id
  @state_id
end

Class Method Details

.find_all_by_office_and_state(office, state) ⇒ Object



24
25
26
# File 'lib/vote_smart/district.rb', line 24

def self.find_all_by_office_and_state office, state
  find_all_by_office_id_and_state_id(office.id, state.id)
end

.find_all_by_office_id_and_state_id(office_id, state_id) ⇒ Object



28
29
30
# File 'lib/vote_smart/district.rb', line 28

def self.find_all_by_office_id_and_state_id office_id, state_id
  response_child(get_by_office_state(office_id, state_id), "districtList", "district").collect {|attributes| District.new(attributes)}
end

.get_by_office_state(office_id, state_id = 'NA', district_name = '') ⇒ Object

Returns districts service the office and state provided



33
34
35
# File 'lib/vote_smart/district.rb', line 33

def self.get_by_office_state office_id, state_id = 'NA', district_name = ''
  request("District.getByOfficeState", "officeId" => office_id, "stateId" => state_id, "districtName" => district_name)
end

.get_by_zip(zip5, zip4 = nil) ⇒ Object

Returns districts in the provided zip code, with optional zip+4



38
39
40
# File 'lib/vote_smart/district.rb', line 38

def self.get_by_zip zip5, zip4=nil
  request("District.getByZip", "zip5" => zip5, "zip4" => zip4)
end

Instance Method Details

#numberObject



11
12
13
14
15
16
17
18
# File 'lib/vote_smart/district.rb', line 11

def number
  return unless name
  
  scan = name.scan(/District (\d[0-9]*)/) || []
  scan = scan.first || []
  num = scan.first
  num ? num.to_i : nil
end

#officialObject



20
21
22
# File 'lib/vote_smart/district.rb', line 20

def official
  @official ||= Official.find_by_district(self)
end