Class: Wordle
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Wordle
- Defined in:
- app/models/wordle.rb
Overview
This model represents the daily Wordle plays.
Instance Attribute Summary collapse
-
#play_date ⇒ Date
The date for which the word is to be set.
-
#skip_today_validation ⇒ Boolean
Flag used to specifiy that validating play_date in the past should be skipped.
-
#word ⇒ String
The word to be set as the solution for a given date.
Instance Method Summary collapse
-
#skip_today_validation? ⇒ Boolean
Flag to allow new Wordle Plays to be created in the past, used to set today’s play if a Puzzle Setter hasn’t set it beforehand.
-
#valid_date_after_today ⇒ Object
Validates that the play_date is not in the past (including today).
-
#valid_date_within_two_weeks ⇒ Object
Validates that the play_date is not beyond two weeks into the future.
-
#valid_solution ⇒ Object
Validates that the word exists in WordleDictionary as a valid solution.
Instance Attribute Details
#play_date ⇒ Date
The date for which the word is to be set
11 12 13 |
# File 'app/models/wordle.rb', line 11 def play_date @play_date end |
#skip_today_validation ⇒ Boolean
Flag used to specifiy that validating play_date in the past should be skipped.
11 12 13 |
# File 'app/models/wordle.rb', line 11 def skip_today_validation @skip_today_validation end |
#word ⇒ String
The word to be set as the solution for a given date
11 12 13 |
# File 'app/models/wordle.rb', line 11 def word @word end |
Instance Method Details
#skip_today_validation? ⇒ Boolean
Flag to allow new Wordle Plays to be created in the past, used to set today’s play if a Puzzle Setter hasn’t set it beforehand
36 37 38 |
# File 'app/models/wordle.rb', line 36 def skip_today_validation? skip_today_validation == true end |
#valid_date_after_today ⇒ Object
Validates that the play_date is not in the past (including today)
26 27 28 |
# File 'app/models/wordle.rb', line 26 def valid_date_after_today errors.add(:play_date, "has to be in the future") if play_date <= Date.today end |
#valid_date_within_two_weeks ⇒ Object
Validates that the play_date is not beyond two weeks into the future
31 32 33 |
# File 'app/models/wordle.rb', line 31 def valid_date_within_two_weeks errors.add(:play_date, "has to be within the next 2 weeks") if play_date > Date.today+14 end |
#valid_solution ⇒ Object
Validates that the word exists in WordleDictionary as a valid solution
21 22 23 |
# File 'app/models/wordle.rb', line 21 def valid_solution errors.add(:word, "is not a valid wordle solution") if WordleDictionary.where(word: word, is_valid_solution: true).empty? end |