<commit_before>module FecResults
  class President

    attr_reader :year, :url

    def initialize(params={})
      params.each_pair do |k,v|
       instance_variable_set("@#{k}", v)
      end
      @url = FecResults::PRESIDENT_URLS[year.to_s]
    end
    
    def to_s
      "#<FecResults::President:#{year.to_s}>"
    end
    
    #### main instance methods called with optional arguments to filter.
    
    def popular_vote_summary(*args)
      send("popular_vote_summary_#{year}", *args)
    end

    def state_electoral_and_popular_vote_summary(*args)
      send("state_electoral_and_popular_vote_summary_#{year}", *args)
    end
    
    def primary_party_summary
      send("primary_party_summary_#{year}")
    end

    def general_election_results(*args)
      send("general_election_results_#{year}", *args)
    end

    def primary_election_results(*args)
      send("primary_election_results_#{year}", *args)
    end
    
    #### cycle-specific methods called by main methods above

    def popular_vote_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 1. 2012 Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate (Party Label)'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate (Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end

    def popular_vote_summary_2008(options={})
      results = []
      t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end
    
    def popular_vote_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 2. Electoral &  Pop Vote', :skip => 4, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row[0], :democratic_electoral_votes => row[1].to_i, :republican_electoral_votes => row[2].to_i, :democratic_popular_votes => row[3].to_i, :republican_popular_votes => row[4].to_i, :other_popular_votes => row[5].to_i, :total_votes => row[6].to_i)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2008(options={})
      results = []
      t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
      end
      results
    end

    def primary_party_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2012 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes:'
        results << OpenStruct.new(party => row[0], :total_votes => row[1].to_i)
      end
      results
    end
    
    def primary_party_summary_2008(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2008 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes:'
        results << OpenStruct.new(party => row[0], :total_votes => row[1].to_i)
      end
      results
    end
    
    def primary_party_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2004 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes Cast:'
        results << OpenStruct.new(party => row[0], :total_votes => row[1].to_i)
      end
      results
    end

    def general_election_results_2012(options={})<commit_msg>fixed party primary summary methods<commit_after>module FecResults
  class President

    attr_reader :year, :url

    def initialize(params={})
      params.each_pair do |k,v|
       instance_variable_set("@#{k}", v)
      end
      @url = FecResults::PRESIDENT_URLS[year.to_s]
    end
    
    def to_s
      "#<FecResults::President:#{year.to_s}>"
    end
    
    #### main instance methods called with optional arguments to filter.
    
    def popular_vote_summary(*args)
      send("popular_vote_summary_#{year}", *args)
    end

    def state_electoral_and_popular_vote_summary(*args)
      send("state_electoral_and_popular_vote_summary_#{year}", *args)
    end
    
    def primary_party_summary
      send("primary_party_summary_#{year}")
    end

    def general_election_results(*args)
      send("general_election_results_#{year}", *args)
    end

    def primary_election_results(*args)
      send("primary_election_results_#{year}", *args)
    end
    
    #### cycle-specific methods called by main methods above

    def popular_vote_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 1. 2012 Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate (Party Label)'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate (Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end

    def popular_vote_summary_2008(options={})
      results = []
      t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end
    
    def popular_vote_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 1. Pres Popular Vote', :skip => 3)
      t.entries.each do |row|
        break if row['Candidate'] == 'Total:'
        results << OpenStruct.new(:candidate => row['Candidate'], :party => row['(Party Label)'], :popular_votes => row['Popular Vote Total'].to_i, :popular_vote_percent => row['Percent of Popular Vote'].to_f)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 2. Electoral &  Pop Vote', :skip => 4, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row[0], :democratic_electoral_votes => row[1].to_i, :republican_electoral_votes => row[2].to_i, :democratic_popular_votes => row[3].to_i, :republican_popular_votes => row[4].to_i, :other_popular_votes => row[5].to_i, :total_votes => row[6].to_i)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2008(options={})
      results = []
      t = RemoteTable.new(FecResults::SUMMARY_URLS[year.to_s], :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
      end
      results
    end

    def state_electoral_and_popular_vote_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => 'Table 2. Pres Elec & Pop Vote', :skip => 2)
      t.entries.each do |row|
        break if row[0] == 'Total:'
        results << OpenStruct.new(:state => row['STATE'], :democratic_electoral_votes => row['Electoral Vote Kerry (D)'].to_i, :republican_electoral_votes => row['Electoral Vote Bush (R)'].to_i, :democratic_popular_votes => row['Popular Vote Kerry (D)'].to_i, :republican_popular_votes => row['Popular Vote Bush (R)'].to_i, :other_popular_votes => row['Popular Vote All Others'].to_i, :total_votes => row['Popular Vote Total Vote'].to_i)
      end
      results
    end

    def primary_party_summary_2012(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2012 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes:'
        results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
      end
      results
    end
    
    def primary_party_summary_2008(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2008 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes:'
        results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
      end
      results
    end
    
    def primary_party_summary_2004(options={})
      results = []
      t = RemoteTable.new(url, :sheet => '2004 Pres Primary Party Summary', :skip => 1, :headers => false)
      t.entries.each do |row|
        break if row[0] == 'Total Primary Votes Cast:'
        results << OpenStruct.new(:party => row[0], :total_votes => row[1].to_i)
      end
      results
    end

    def primary_party_summary_2000(options={})
      raise NotImplementedError.new("Data not available for #{year}")
    end

    def general_election_results_2012(options={})
{'fraction_non_alphanumeric': 0.1437702477891603, 'fraction_numerical': 0.016110673321075214, 'mean_word_length': 3.372894333843798, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2240147', 'n_tokens_mistral': 3941, 'n_tokens_neox': 3665, 'n_words': 874}