class AeEasy::Qa::ValidateValue

Attributes

data_hash[R]
errored_item[R]
field_to_validate[R]
params[R]

Public Class Methods

new(data_hash, field_to_validate, params, errored_item) click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 8
def initialize(data_hash, field_to_validate, params, errored_item)
  @data_hash = data_hash
  @field_to_validate = field_to_validate
  @params = params
  @errored_item = errored_item
end

Public Instance Methods

run() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 15
def run
  if_exists? ? handle_if : main_value_check
end

Private Instance Methods

equal_operator() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 62
def equal_operator
  params['equal'].keys.first
end
equal_with_operators() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 47
def equal_with_operators
  case equal_operator
  when 'or'
    add_errored_item(data_hash, field_to_validate, 'value') if !or_statment
  end
end
equal_with_operators?() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 58
def equal_with_operators?
  params['equal'].class == Hash
end
handle_if() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 25
def handle_if
  main_value_check if pass_if?(params['if'], data_hash)
end
if_exists?() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 21
def if_exists?
  !params['if'].nil?
end
main_value_check() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 29
def main_value_check
  if params['equal']
    if equal_with_operators?
      equal_with_operators
    else
      add_errored_item(data_hash, field_to_validate, 'value') if (data_hash[field_to_validate] != params['equal'])
    end
  elsif params['regex']
    add_errored_item(data_hash, field_to_validate, 'value') if (data_hash[field_to_validate].to_s !~ Regexp.new(params['regex'], true))
  elsif params['less_than']
    add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate].to_i < params['less_than'].to_i)
  elsif params['greater_than']
    add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate].to_i > params['greater_than'].to_i)
  else
    unknown_value_error
  end
end
or_statment() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 54
def or_statment
  eval or_vals.map{|val| "data_hash[field_to_validate] == #{val}" }.join(' || ')
end
or_vals() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 66
def or_vals
  params['equal']['or']
end
unknown_value_error() click to toggle source
# File lib/ae_easy/qa/validate_value.rb, line 70
def unknown_value_error
  raise StandardError.new("The value rule '#{params}' is unknown.")
end