Class: TwentySixteen::Candidate
- Inherits:
-
Object
- Object
- TwentySixteen::Candidate
- Defined in:
- lib/twenty_sixteen/candidate.rb
Constant Summary collapse
- CANDIDATES_JSON =
File.dirname(__FILE__) + '/candidates.json'
Class Method Summary collapse
- .active ⇒ Object
- .all ⇒ Object
- .democrat ⇒ Object
-
.find_by_last_name(last_name) ⇒ Object
assumes uniqueness of last_names…
- .find_by_url(url) ⇒ Object
- .independent ⇒ Object
- .republican ⇒ Object
- .where(options) ⇒ Object
Class Method Details
.active ⇒ Object
12 13 14 |
# File 'lib/twenty_sixteen/candidate.rb', line 12 def self.active all.select{|candidate| candidate[:campaign_status] == "active"} end |
.all ⇒ Object
8 9 10 |
# File 'lib/twenty_sixteen/candidate.rb', line 8 def self.all JSON.parse(File.read(CANDIDATES_JSON), :symbolize_names => true) end |
.democrat ⇒ Object
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 |
.independent ⇒ Object
24 25 26 |
# File 'lib/twenty_sixteen/candidate.rb', line 24 def self.independent all.select{|candidate| candidate[:party] == "Independent"} end |
.republican ⇒ Object
20 21 22 |
# File 'lib/twenty_sixteen/candidate.rb', line 20 def self.republican all.select{|candidate| candidate[:party] == "Republican"} end |
.where(options) ⇒ Object
39 40 41 |
# File 'lib/twenty_sixteen/candidate.rb', line 39 def self.where() all.select{|candidate| candidate.merge() == candidate} end |