class Either

Public Class Methods

new(first_field, second_field, validator_class, *params) click to toggle source
# 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

Public Instance Methods

params() click to toggle source
# File lib/sanatio/built-in/either.rb, line 26
def params
  [@first_field, @second_field]
end
reason(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/sanatio/built-in/either.rb, line 12
def valid?(value)
  !both?(value) && !neither?(value)
end

Private Instance Methods

both?(value) click to toggle source
# File lib/sanatio/built-in/either.rb, line 32
def both?(value)
  @validator.valid?(first_value(value)) && @validator.valid?(second_value(value))
end
first_value(value) click to toggle source
# File lib/sanatio/built-in/either.rb, line 40
def first_value(value)
  value.send(@first_field)
end
neither?(value) click to toggle source
# File lib/sanatio/built-in/either.rb, line 36
def neither?(value)
  !@validator.valid?(first_value(value)) && !@validator.valid?(second_value(value))
end
second_value(value) click to toggle source
# File lib/sanatio/built-in/either.rb, line 44
def second_value(value)
  value.send(@second_field)
end