Module: Codebreaker::Validation
- Defined in:
- lib/codebraker_ov/utils/validation.rb
Class Method Summary collapse
- .answer_valid?(guess) ⇒ Boolean
-
.name_length_valid?(name) ⇒ Boolean
rubocop:enable Style/GuardClause.
-
.name_valid?(name) ⇒ Boolean
cause guard clause will be > 80 chars rubocop:disable Style/GuardClause.
- .string?(item) ⇒ Boolean
Class Method Details
.answer_valid?(guess) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/codebraker_ov/utils/validation.rb', line 11 def self.answer_valid?(guess) unless string?(guess) && guess.match?(/^[123456]{4}$/) raise Codebreaker::Errors::AnswerError end end |
.name_length_valid?(name) ⇒ Boolean
rubocop:enable Style/GuardClause
18 19 20 |
# File 'lib/codebraker_ov/utils/validation.rb', line 18 def self.name_length_valid?(name) name.length > 2 && name.length < 21 end |
.name_valid?(name) ⇒ Boolean
cause guard clause will be > 80 chars rubocop:disable Style/GuardClause
5 6 7 8 9 |
# File 'lib/codebraker_ov/utils/validation.rb', line 5 def self.name_valid?(name) unless string?(name) && name_length_valid?(name) raise Codebreaker::Errors::NameError end end |
.string?(item) ⇒ Boolean
22 23 24 |
# File 'lib/codebraker_ov/utils/validation.rb', line 22 def self.string?(item) item.instance_of?(String) end |