class TwentySixteen::Candidate

Constants

CANDIDATES_JSON

Public Class Methods

active() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 12
def self.active
  all.select{|candidate| candidate[:campaign_status] == "active"}
end
all() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 8
def self.all
  JSON.parse(File.read(CANDIDATES_JSON), :symbolize_names => true)
end
democrat() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 16
def self.democrat
  all.select{|candidate| candidate[:party] == "Democrat"}
end
find_by_last_name(last_name) click to toggle source

assumes uniqueness of last_names…

# File lib/twenty_sixteen/candidate.rb, line 33
def self.find_by_last_name(last_name)
  all.find{|candidate| candidate[:last_name] == last_name}
end
find_by_url(url) click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 28
def self.find_by_url(url)
  all.find{|candidate| candidate[:url] == url}
end
independent() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 24
def self.independent
  all.select{|candidate| candidate[:party] == "Independent"}
end
party_nominee() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 43
def self.party_nominee
  all.select{|candidate| candidate[:party_nominee] == true}
end
republican() click to toggle source
# File lib/twenty_sixteen/candidate.rb, line 20
def self.republican
  all.select{|candidate| candidate[:party] == "Republican"}
end
where(options) click to toggle source

@param [Hash] options @example .where({:party=>“Independent”, :first_name=>“Jim”})

# File lib/twenty_sixteen/candidate.rb, line 39
def self.where(options)
  all.select{|candidate| candidate.merge(options) == candidate}
end