Sha256: 15b098e57d686035e82c343fab7c2a8b5392a0b54fea3a4c2429e54e1d19c8cf
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
class FindRepresentatives def initialize(sen1, sen2, rep, elements, address) # Grab district number for Representative display @district = rep[2].scan(/\d/)[0] # create hashes for each senator and representative senator1 = {} senator2 = {} representative = {} congress_members = [senator1, senator2, representative] info_array = [sen1, sen2, rep] # extract info from scraped elements and organize into hashes x = 0 congress_members.each do |member| member[:name] = info_array[x][0].strip member[:party] = info_array[x][1].scan(/.[RD]\W/)[0] if member[:party] == "(R)" member[:party] = "Republican" else member[:party] = "Democrat" end member[:phone] = info_array[x][3].strip member[:twitter] = elements.css("div.oa-eo-target-col-links")[x+3].children[1].attributes["href"].value member[:facebook] = elements.css("div.oa-eo-target-col-links")[x+3].children[3].attributes["href"].value member[:website] = elements.css("div.oa-eo-target-col-links")[x+3].children[5].attributes["href"].value x += 1 end # Send organized hashes, district, and address hash to # CongressOutput method for output CongressOutput.new(senator1, senator2, representative, @district, address) end end
Version data entries
5 entries across 5 versions & 1 rubygems