Sha256: 3628fabb6bf1e8d6a57acf740e9c2853b7f9cb44c3b160e2431756ac181a3ca2

Contents?: true

Size: 1.45 KB

Versions: 12

Compression:

Stored size: 1.45 KB

Contents

class FindRepresentatives

    def initialize(sen1, sen2, rep, elements, state)
        # 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 state to 
        # CongressOutput method for output
        CongressOutput.new(senator1, senator2, representative, @district, state)



    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
my-congress-0.2.2 lib/find_representatives.rb
my-congress-0.2.1 lib/find_representatives.rb
my-congress-0.2.0 lib/find_representatives.rb
my-congress-0.1.9 lib/find_representatives.rb
my-congress-0.1.8 lib/find_representatives.rb
my-congress-0.1.7 lib/find_representatives.rb
my-congress-0.1.6 lib/find_representatives.rb
my-congress-0.1.5 lib/find_representatives.rb
my-congress-0.1.4 lib/find_representatives.rb
my-congress-0.1.3 lib/find_representatives.rb
my-congress-0.1.2 lib/find_representatives.rb
my-congress-0.1.1 lib/find_representatives.rb