Class: Either
- Inherits:
-
Object
- Object
- Either
- Defined in:
- lib/sanatio/built-in/either.rb
Instance Method Summary collapse
-
#initialize(first_field, second_field, validator_class, *params) ⇒ Either
constructor
A new instance of Either.
- #params ⇒ Object
- #reason(value) ⇒ Object
- #skip?(value) ⇒ Boolean
- #valid?(value) ⇒ Boolean
Constructor Details
#initialize(first_field, second_field, validator_class, *params) ⇒ Either
Returns a new instance of Either.
2 3 4 5 6 |
# File 'lib/sanatio/built-in/either.rb', line 2 def initialize(first_field, second_field, validator_class, *params) @first_field = first_field @second_field = second_field @validator = validator_class.new(*params) end |
Instance Method Details
#params ⇒ Object
26 27 28 |
# File 'lib/sanatio/built-in/either.rb', line 26 def params [@first_field, @second_field] end |
#reason(value) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/sanatio/built-in/either.rb', line 16 def reason(value) if neither?(value) :neither else if both?(value) :both end end end |
#skip?(value) ⇒ Boolean
8 9 10 |
# File 'lib/sanatio/built-in/either.rb', line 8 def skip?(value) @validator.skip?(first_value(value)) || @validator.skip?(second_value(value)) end |
#valid?(value) ⇒ Boolean
12 13 14 |
# File 'lib/sanatio/built-in/either.rb', line 12 def valid?(value) !both?(value) && !neither?(value) end |