Class: SportsManager::TournamentDay::Validator
- Extended by:
- Forwardable
- Defined in:
- lib/sports_manager/tournament_day/validator.rb
Overview
Public: Validates tournament day’s date and time range
Constant Summary collapse
- DateParsingError =
Class.new(StandardError) do def initialize(date) = "It is not possible to parse Date: #{date}" super() end end
- InvalidHour =
Class.new(StandardError) do def initialize(start_hour, end_hour) = 'start_hour and end_hour must be between 0 and 23. ' \ "start_hour: #{start_hour}, end_hour: #{end_hour}" super() end end
- MIN_HOUR =
0- MAX_HOUR =
23
Instance Attribute Summary collapse
-
#tournament_day ⇒ Object
readonly
Returns the value of attribute tournament_day.
Instance Method Summary collapse
-
#initialize(tournament_day) ⇒ Validator
constructor
A new instance of Validator.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
Constructor Details
#initialize(tournament_day) ⇒ Validator
Returns a new instance of Validator.
31 32 33 |
# File 'lib/sports_manager/tournament_day/validator.rb', line 31 def initialize(tournament_day) @tournament_day = tournament_day end |
Instance Attribute Details
#tournament_day ⇒ Object (readonly)
Returns the value of attribute tournament_day.
27 28 29 |
# File 'lib/sports_manager/tournament_day/validator.rb', line 27 def tournament_day @tournament_day end |
Instance Method Details
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/sports_manager/tournament_day/validator.rb', line 42 def valid? parseable_date? && in_day_range? end |
#validate! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/sports_manager/tournament_day/validator.rb', line 35 def validate! return true if valid? raise DateParsingError, date unless parseable_date? raise InvalidHour.new(start_hour, end_hour) end |