Module: AeEasy::Qa::Helpers
- Included in:
- ValidateRules, ValidateType, ValidateValue
- Defined in:
- lib/ae_easy/qa/helpers.rb
Instance Method Summary collapse
- #add_errored_item(data_hash, field_to_validate, validation) ⇒ Object
- #evaluate_condition(field_name, condition_hash, data_hash) ⇒ Object
- #pass_if?(if_params, data_hash) ⇒ Boolean
Instance Method Details
#add_errored_item(data_hash, field_to_validate, validation) ⇒ Object
4 5 6 7 8 |
# File 'lib/ae_easy/qa/helpers.rb', line 4 def add_errored_item(data_hash, field_to_validate, validation) error_name = "#{field_to_validate}_#{validation}" errored_item[:failures][error_name.to_sym] = 'fail' errored_item[:item] = data_hash if errored_item[:data].nil? end |
#evaluate_condition(field_name, condition_hash, data_hash) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ae_easy/qa/helpers.rb', line 27 def evaluate_condition(field_name, condition_hash, data_hash) case condition_hash.keys.first when 'value' value_hash = condition_hash['value'] #Ex: {"equal"=>"A"} if value_hash['equal'] data_hash[field_name] == value_hash['equal'] elsif value_hash['regex'] !(data_hash[field_name].to_s =~ Regexp.new(value_hash['regex'], true)).nil? elsif value_hash['less_than'] data_hash[field_name].to_i < value_hash['less_than'].to_i elsif value_hash['greater_than'] data_hash[field_name].to_i > value_hash['greater_than'].to_i else raise StandardError.new("The if condition '#{value_hash}' is unknown.") end end end |
#pass_if?(if_params, data_hash) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ae_easy/qa/helpers.rb', line 10 def pass_if?(if_params, data_hash) case if_params.keys.first when 'and', 'or' operator = if_params.keys.first evaluations = if_params[operator].collect{|child_if_params| field_name = child_if_params.keys.first condition_hash = child_if_params[field_name] evaluate_condition(field_name, condition_hash, data_hash) } operator == 'and' ? evaluations.all? : evaluations.any? else field_name = if_params.keys.first condition_hash = if_params[field_name] evaluate_condition(field_name, condition_hash, data_hash) end end |