Class: Hulse::SenateVote

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ SenateVote

Returns a new instance of SenateVote.



7
8
9
10
11
# File 'lib/hulse/senate_vote.rb', line 7

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

Instance Attribute Details

#amendmentObject (readonly)

Returns the value of attribute amendment.



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

def amendment
  @amendment
end

#congressObject (readonly)

Returns the value of attribute congress.



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

def congress
  @congress
end

#documentObject (readonly)

Returns the value of attribute document.



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

def document
  @document
end

#majority_requirementObject (readonly)

Returns the value of attribute majority_requirement.



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

def majority_requirement
  @majority_requirement
end

#membersObject (readonly)

Returns the value of attribute members.



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

def members
  @members
end

#questionObject (readonly)

Returns the value of attribute question.



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

def question
  @question
end

#sessionObject (readonly)

Returns the value of attribute session.



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

def session
  @session
end

#tie_breakerObject (readonly)

Returns the value of attribute tie_breaker.



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

def tie_breaker
  @tie_breaker
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#vote_countObject (readonly)

Returns the value of attribute vote_count.



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

def vote_count
  @vote_count
end

#vote_document_textObject (readonly)

Returns the value of attribute vote_document_text.



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

def vote_document_text
  @vote_document_text
end

#vote_numberObject (readonly)

Returns the value of attribute vote_number.



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

def vote_number
  @vote_number
end

#vote_question_textObject (readonly)

Returns the value of attribute vote_question_text.



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

def vote_question_text
  @vote_question_text
end

#vote_resultObject (readonly)

Returns the value of attribute vote_result.



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

def vote_result
  @vote_result
end

#vote_result_textObject (readonly)

Returns the value of attribute vote_result_text.



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

def vote_result_text
  @vote_result_text
end

#vote_timestampObject (readonly)

Returns the value of attribute vote_timestamp.



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

def vote_timestamp
  @vote_timestamp
end

#vote_titleObject (readonly)

Returns the value of attribute vote_title.



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

def vote_title
  @vote_title
end

#yearObject (readonly)

Returns the value of attribute year.



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

def year
  @year
end

Class Method Details

.create_from_vote(response) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hulse/senate_vote.rb', line 21

def self.create_from_vote(response)
  members = []
  response['members']['member'].each do |m|
    members << m.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
  end
  self.new(:congress => response['congress'].to_i,
    :session => response['session'].to_i,
    :year => response['congress_year'].to_i,
    :vote_number => response['vote_number'].to_i,
    :vote_timestamp => DateTime.parse(response['vote_date']),
    :updated_at => DateTime.parse(response['modify_date']),
    :vote_question_text => response['vote_question_text'],
    :vote_document_text => response['vote_document_text'],
    :vote_result_text => response['vote_result_text'],
    :question => response['question'],
    :vote_title => response['vote_title'],
    :majority_requirement => response['majority_requirement'],
    :vote_result => response['vote_result'],
    :document => response['document'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
    :amendment => response['amendment'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
    :vote_count => response['count'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
    :tie_breaker => response['tie_breaker'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
    :members => members
  )  
end

.find(year, vote) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/hulse/senate_vote.rb', line 13

def self.find(year, vote)
  # TODO: need to special-case 2013 votes from 112th congress, 2nd session
  congress, session = Hulse::Utils.convert_year_to_congress_and_session(year)
  url = "http://www.senate.gov/legislative/LIS/roll_call_votes/vote#{congress.to_s}#{session.to_s}/vote_#{congress.to_s}_#{session.to_s}_#{vote.to_s.rjust(5,"0")}.xml"
  response = HTTParty.get(url)
  self.create_from_vote(response.parsed_response['roll_call_vote'])
end