Module: ElectionDay
- Defined in:
- lib/election_day.rb,
lib/election_day/version.rb
Overview
A library to calculate when U.S. Election Day occurs.
“The Tuesday next after the first Monday in the month of November” – The 28th Congress (memory.loc.gov/ll/llsl/005/0700/07590721.tif)
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is an election year.
-
.midterm_election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is a midterm election year.
-
.next_election ⇒ Date
Returns the date of the next election.
-
.next_midterm_election ⇒ Date
Returns the date of the next midterm election.
-
.next_presidential_election ⇒ Date
Returns the date of the next presidential election.
-
.presidential_election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is a presidential election year.
Class Method Details
.election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is an election year.
13 14 15 |
# File 'lib/election_day.rb', line 13 def self.election_year?(year = Date.today.year) year.even? end |
.midterm_election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is a midterm election year.
21 22 23 |
# File 'lib/election_day.rb', line 21 def self.midterm_election_year?(year = Date.today.year) (year + 2) % 4 == 0 end |
.next_election ⇒ Date
Returns the date of the next election.
36 37 38 |
# File 'lib/election_day.rb', line 36 def self.next_election get_next_election(&:election_year?) end |
.next_midterm_election ⇒ Date
Returns the date of the next midterm election.
43 44 45 |
# File 'lib/election_day.rb', line 43 def self.next_midterm_election get_next_election(&:midterm_election_year?) end |
.next_presidential_election ⇒ Date
Returns the date of the next presidential election.
50 51 52 |
# File 'lib/election_day.rb', line 50 def self.next_presidential_election get_next_election(&:presidential_election_year?) end |
.presidential_election_year?(year = Date.today.year) ⇒ Boolean
Checks whether year is a presidential election year.
29 30 31 |
# File 'lib/election_day.rb', line 29 def self.presidential_election_year?(year = Date.today.year) year % 4 == 0 end |