Class: Hulse::HouseMember

Inherits:
Object
  • Object
show all
Defined in:
lib/hulse/house_member.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ HouseMember

Returns a new instance of HouseMember.



9
10
11
12
13
# File 'lib/hulse/house_member.rb', line 9

def initialize(params={})
  params.each_pair do |k,v|
    instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#bioguide_idObject (readonly)

Returns the value of attribute bioguide_id.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def bioguide_id
  @bioguide_id
end

#caucus_partyObject (readonly)

Returns the value of attribute caucus_party.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def caucus_party
  @caucus_party
end

#committeesObject (readonly)

Returns the value of attribute committees.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def committees
  @committees
end

#courtesyObject (readonly)

Returns the value of attribute courtesy.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def courtesy
  @courtesy
end

#district_codeObject (readonly)

Returns the value of attribute district_code.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def district_code
  @district_code
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def first_name
  @first_name
end

#footnoteObject (readonly)

Returns the value of attribute footnote.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def footnote
  @footnote
end

#formal_nameObject (readonly)

Returns the value of attribute formal_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def formal_name
  @formal_name
end

#hometownObject (readonly)

Returns the value of attribute hometown.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def hometown
  @hometown
end

#is_vacantObject (readonly)

Returns the value of attribute is_vacant.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def is_vacant
  @is_vacant
end

#last_elected_dateObject (readonly)

Returns the value of attribute last_elected_date.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def last_elected_date
  @last_elected_date
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def last_name
  @last_name
end

#middle_nameObject (readonly)

Returns the value of attribute middle_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def middle_name
  @middle_name
end

#office_buildingObject (readonly)

Returns the value of attribute office_building.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def office_building
  @office_building
end

#office_roomObject (readonly)

Returns the value of attribute office_room.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def office_room
  @office_room
end

#office_zipObject (readonly)

Returns the value of attribute office_zip.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def office_zip
  @office_zip
end

#official_nameObject (readonly)

Returns the value of attribute official_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def official_name
  @official_name
end

#partyObject (readonly)

Returns the value of attribute party.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def party
  @party
end

#phoneObject (readonly)

Returns the value of attribute phone.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def phone
  @phone
end

#predecessorObject (readonly)

Returns the value of attribute predecessor.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def predecessor
  @predecessor
end

#sort_nameObject (readonly)

Returns the value of attribute sort_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def sort_name
  @sort_name
end

#state_nameObject (readonly)

Returns the value of attribute state_name.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def state_name
  @state_name
end

#state_postalObject (readonly)

Returns the value of attribute state_postal.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def state_postal
  @state_postal
end

#subcommitteesObject (readonly)

Returns the value of attribute subcommittees.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def subcommittees
  @subcommittees
end

#suffixObject (readonly)

Returns the value of attribute suffix.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def suffix
  @suffix
end

#sworn_dateObject (readonly)

Returns the value of attribute sworn_date.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def sworn_date
  @sworn_date
end

#vacancy_dateObject (readonly)

Returns the value of attribute vacancy_date.



4
5
6
# File 'lib/hulse/house_member.rb', line 4

def vacancy_date
  @vacancy_date
end

Class Method Details

.create_from_xml(response) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hulse/house_member.rb', line 22

def self.create_from_xml(response)
  members = []
  response['MemberData']['members']['member'].each do |member|
    if member['member_info']['elected_date']['date'] == ''
      footnote = member['member_info']['footnote']
      predecessor = member['predecessor_info']
      vacancy_date = Date.parse(member['predecessor_info']['pred_vacate_date']['date'])
      vacant = true
    else
      footnote, predecessor, vacancy_date = nil
      vacant = false
    end

    members << self.new(bioguide_id: member['member_info']['bioguideID'],
      sort_name: member['member_info']['sort_name'],
      last_name: member['member_info']['lastname'],
      first_name: member['member_info']['firstname'],
      middle_name: member['member_info']['middlename'],
      suffix: member['member_info']['suffix'],
      courtesy: member['member_info']['courtesy'],
      official_name: member['member_info']['official_name'],
      formal_name: member['member_info']['formal_name'],
      party: member['member_info']['party'],
      caucus_party: member['member_info']['caucus'],
      state_postal: member['member_info']['state']['postal_code'],
      state_name: member['member_info']['state']['state_fullname'],
      district: member['member_info']['district'],
      district_code: member['statedistrict'],
      hometown: member['member_info']['townname'],
      office_building: member['member_info']['office_building'],
      office_room: member['member_info']['office_room'],
      office_zip: member['member_info']['office_zip']+'-'+member['member_info']['office_zip_suffix'],
      phone: member['member_info']['phone'],
      last_elected_date: begin Date.parse(member['member_info']['elected_date']['date']) rescue nil end,
      sworn_date: begin Date.parse(member['member_info']['sworn_date']['date']) rescue nil end,
      committees: member['committee_assignments']['committee'],
      subcommittees: member['committee_assignments']['subcommittee'],
      is_vacant: vacant,
      footnote: footnote,
      predecessor: predecessor,
      vacancy_date: vacancy_date
    )
  end
  members
end

.currentObject



15
16
17
18
19
# File 'lib/hulse/house_member.rb', line 15

def self.current
  url = "http://clerk.house.gov/xml/lists/MemberData.xml"
  response = HTTParty.get(url)
  self.create_from_xml(response)
end