Class: WashoePolls::Client
- Inherits:
-
Object
- Object
- WashoePolls::Client
- Defined in:
- lib/washoe_polls/client.rb
Instance Method Summary collapse
- #fetch(voter_id) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #lookup(last_name, birth_date) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
4 5 |
# File 'lib/washoe_polls/client.rb', line 4 def initialize() end |
Instance Method Details
#fetch(voter_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/washoe_polls/client.rb', line 21 def fetch(voter_id) response = get "http://www.co.washoe.nv.us/voters/regsearch.php~details=#{voter_id}" doc = Nokogiri::HTML(response) doc.css('br').each{ |br| br.replace("\n") } nodes = doc.xpath('//table')[1].xpath('tr//td[2]') info = { :name => nodes[0].content, :birth_date => nodes[1].content, :precinct => nodes[2].content, :place => nodes[3].content.gsub(/\nclick for directions/,''), :address => nodes[4].content, :party => nodes[5].content, :registered => nodes[6].content } end |
#lookup(last_name, birth_date) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/washoe_polls/client.rb', line 7 def lookup(last_name,birth_date) post_vars = { :submit => "on", :color => "blue", :text_version => "", :Last => last_name, :Birth => birth_date } response = post 'http://www.co.washoe.nv.us/voters/regsearch.php', post_vars doc = Nokogiri::HTML(response) id = /.*?~details=(\d+)&/.match(doc.xpath('//table')[1].xpath('tr')[1].at_xpath('td/a').attr('href'))[1] id.to_i end |