Class: TwentySixteen::Candidate

Inherits:
Object
  • Object
show all
Defined in:
lib/twenty_sixteen/candidate.rb

Constant Summary collapse

CANDIDATES_JSON =
File.dirname(__FILE__) + '/candidates.json'

Class Method Summary collapse

Class Method Details

.activeObject



12
13
14
# File 'lib/twenty_sixteen/candidate.rb', line 12

def self.active
  all.select{|candidate| candidate[:campaign_status] == "active"}
end

.allObject



8
9
10
# File 'lib/twenty_sixteen/candidate.rb', line 8

def self.all
  JSON.parse(File.read(CANDIDATES_JSON), :symbolize_names => true)
end

.democratObject



16
17
18
# File 'lib/twenty_sixteen/candidate.rb', line 16

def self.democrat
  all.select{|candidate| candidate[:party] == "Democrat"}
end

.find_by_last_name(last_name) ⇒ Object

assumes uniqueness of last_names…



33
34
35
# 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) ⇒ Object



28
29
30
# File 'lib/twenty_sixteen/candidate.rb', line 28

def self.find_by_url(url)
  all.find{|candidate| candidate[:url] == url}
end

.independentObject



24
25
26
# File 'lib/twenty_sixteen/candidate.rb', line 24

def self.independent
  all.select{|candidate| candidate[:party] == "Independent"}
end

.republicanObject



20
21
22
# File 'lib/twenty_sixteen/candidate.rb', line 20

def self.republican
  all.select{|candidate| candidate[:party] == "Republican"}
end

.where(options) ⇒ Object

Examples:

.where(:first_name=>“Jim”)

Parameters:

  • options (Hash)


39
40
41
# File 'lib/twenty_sixteen/candidate.rb', line 39

def self.where(options)
  all.select{|candidate| candidate.merge(options) == candidate}
end