ae_easy-qa 0.0.28 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 1e3e0d4eb58a9471e48a6f2fd1dbd628f50d52ad608f135a787109bfec147b23
4
- data.tar.gz: f780351ad816a33b67d2312ce554852b10288d24a6d9c0bf3892c543e1c1f214
2
+ SHA1:
3
+ metadata.gz: e5541353f16b04175786b1ceb92a0e767032bbf7
4
+ data.tar.gz: 54910859a41cbfbe7aed8c21d719b44f48bca999
5
5
  SHA512:
6
- metadata.gz: b2514ac3b1ca295ff59003ce3e79472dddb20e98a6257777f2c3e6427ada51944e7d620958e549a42d62c99f4336dc9f716964f84c5464fbe0bffba362f41aa6
7
- data.tar.gz: 55d0bdeb9eb474d8c6aae60e60ec6180ee1e5ca3c991f206ce2176eb2a55b76fb5bdcc5e8c1c4b6f06a923d3bc4184502aa1640f8a327990c1b23e94a9f884c1
6
+ metadata.gz: 2c6b03b3151a72afd8c7e927c77e91f6ea92e1cc10944be3c5a7de93ec63cd38143d0937e83aeb93ee37e13076026b0b6dfb69f7e69ed78be360f53da9699ff6
7
+ data.tar.gz: 96bbb90dd55a2ba8ccaaf44c5f68efd0770a34c51184dfff24575c840ba54d047f80990b16dbc827be7f23a788361ba5ea5ee17e4d17c6d7865688d6795c53d7
@@ -22,10 +22,12 @@ module AeEasy
22
22
  @data = data
23
23
  end
24
24
 
25
+ #this method is for validating "internal" scrapers that run on AnswersEngine
25
26
  def validate_internal(vars, outputs)
26
27
  ValidateInternal.new(vars, config, outputs).run
27
28
  end
28
29
 
30
+ #this method is for validating data from "external" sources
29
31
  def validate_external(outputs, collection_name)
30
32
  ValidateExternal.new(data, config, outputs, collection_name, options).run
31
33
  end
@@ -6,6 +6,41 @@ module AeEasy
6
6
  errored_item[:failures][error_name.to_sym] = 'fail'
7
7
  errored_item[:item] = data_hash if errored_item[:data].nil?
8
8
  end
9
+
10
+ def pass_if?(if_params, data_hash)
11
+ case if_params.keys.first
12
+ when 'and', 'or'
13
+ operator = if_params.keys.first
14
+ evaluations = if_params[operator].collect{|child_if_params|
15
+ field_name = child_if_params.keys.first
16
+ condition_hash = child_if_params[field_name]
17
+ evaluate_condition(field_name, condition_hash, data_hash)
18
+ }
19
+ operator == 'and' ? evaluations.all? : evaluations.any?
20
+ else
21
+ field_name = if_params.keys.first
22
+ condition_hash = if_params[field_name]
23
+ evaluate_condition(field_name, condition_hash, data_hash)
24
+ end
25
+ end
26
+
27
+ def evaluate_condition(field_name, condition_hash, data_hash)
28
+ case condition_hash.keys.first
29
+ when 'value'
30
+ value_hash = condition_hash['value'] #Ex: {"equal"=>"A"}
31
+ if value_hash['equal']
32
+ data_hash[field_name] == value_hash['equal']
33
+ elsif value_hash['regex']
34
+ !(data_hash[field_name].to_s =~ Regexp.new(value_hash['regex'], true)).nil?
35
+ elsif value_hash['less_than']
36
+ data_hash[field_name].to_i < value_hash['less_than'].to_i
37
+ elsif value_hash['greater_than']
38
+ data_hash[field_name].to_i > value_hash['greater_than'].to_i
39
+ else
40
+ raise StandardError.new("The if condition '#{value_hash}' is unknown.")
41
+ end
42
+ end
43
+ end
9
44
  end
10
45
  end
11
46
  end
@@ -28,6 +28,7 @@ module AeEasy
28
28
 
29
29
  private
30
30
 
31
+ #thresholds are a setting where you can ignore errors if they are under a specific error rate
31
32
  def gather_threshold_totals
32
33
  rules.each{|field_to_validate, field_options|
33
34
  field_threshold = return_threshold(field_to_validate, field_options)
@@ -1,18 +1,19 @@
1
1
  module AeEasy
2
2
  module Qa
3
3
  class ValidateInternal
4
- attr_reader :scraper_name, :collections, :rules, :outputs
4
+ attr_reader :scraper_name, :collections, :rules, :outputs, :data
5
5
 
6
6
  def initialize(vars, config, outputs)
7
7
  @scraper_name = vars['scraper_name']
8
8
  @collections = vars['collections']
9
9
  @rules = config['individual_validations']
10
10
  @outputs = outputs
11
+ @data = vars['data']
11
12
  end
12
13
 
13
14
  def run
14
15
  begin
15
- ValidateScraper.new(scraper_name, collections, rules, outputs, thresholds).run
16
+ ValidateScraper.new(scraper_name, collections, rules, outputs, thresholds, data).run
16
17
  rescue StandardError => e
17
18
  puts "An error has occurred: #{e}"
18
19
  return nil
@@ -21,6 +22,7 @@ module AeEasy
21
22
 
22
23
  private
23
24
 
25
+ #thresholds are a setting where you can suppress errors if they are under a specific error rate
24
26
  def thresholds
25
27
  @thresholds ||= begin
26
28
  file_path = File.expand_path('thresholds.yaml', Dir.pwd)
@@ -34,14 +36,15 @@ module AeEasy
34
36
  end
35
37
 
36
38
  class ValidateScraper
37
- attr_reader :scraper_name, :collections, :rules, :outputs, :options
39
+ attr_reader :scraper_name, :collections, :rules, :outputs, :options, :data
38
40
 
39
- def initialize(scraper_name, collections, rules, outputs, thresholds)
41
+ def initialize(scraper_name, collections, rules, outputs, thresholds, data)
40
42
  @scraper_name = scraper_name
41
43
  @collections = collections
42
44
  @rules = rules
43
45
  @outputs = outputs
44
46
  @options = {}
47
+ @data = data
45
48
  options['thresholds'] = thresholds[scraper_name] if thresholds && thresholds[scraper_name]
46
49
  end
47
50
 
@@ -74,7 +77,7 @@ module AeEasy
74
77
  collections.each do |collection_name|
75
78
  collection = collection_counts.find{|collection_hash| collection_hash['collection'] == collection_name }
76
79
  if collection
77
- ValidateCollection.new(scraper_name, collection_name, collection['outputs'], rules, outputs, options).run
80
+ ValidateCollection.new(scraper_name, collection_name, collection['outputs'], rules, outputs, options.merge({'data' => @data})).run
78
81
  else
79
82
  puts "collection #{collection_name} is missing"
80
83
  end
@@ -107,6 +110,7 @@ module AeEasy
107
110
  @total_records = total_records
108
111
  @rules = rules
109
112
  @outputs = outputs
113
+ @data = options['data']
110
114
  @options = options
111
115
  @errors = { errored_items: [] }
112
116
  end
@@ -27,12 +27,12 @@ module AeEasy
27
27
  options.each{|validation, value|
28
28
  case validation
29
29
  when 'type'
30
- ValidateType.new(data_hash, field_to_validate, value, rules, errored_item).run if options['required']
30
+ ValidateType.new(data_hash, field_to_validate, value, rules, errored_item).run
31
31
  when 'value'
32
- ValidateValue.new(data_hash, field_to_validate, value, errored_item).run if options['required']
32
+ ValidateValue.new(data_hash, field_to_validate, value, errored_item).run
33
33
  when 'length'
34
- validate_length(data_hash, field_to_validate, value) if options['required']
35
- when /required|threshold/
34
+ validate_length(data_hash, field_to_validate, value)
35
+ when /required|threshold|if/
36
36
  nil
37
37
  else
38
38
  unknown_validation_error(validation) if validation !~ /format/
@@ -45,7 +45,23 @@ module AeEasy
45
45
  end
46
46
 
47
47
  def passes_required_check?(options, data_hash, field_to_validate)
48
- if options['required'] == true && fails_required_check?(data_hash, field_to_validate)
48
+ if options['required'] == true
49
+ if options['if']
50
+ if pass_if?(options['if'], data_hash)
51
+ check_for_required_failure(data_hash, field_to_validate)
52
+ else
53
+ false
54
+ end
55
+ else
56
+ check_for_required_failure(data_hash, field_to_validate)
57
+ end
58
+ else
59
+ false
60
+ end
61
+ end
62
+
63
+ def check_for_required_failure(data_hash, field_to_validate)
64
+ if fails_required_check?(data_hash, field_to_validate)
49
65
  add_errored_item(data_hash, field_to_validate, 'required')
50
66
  false
51
67
  else
@@ -13,24 +13,17 @@ module AeEasy
13
13
  end
14
14
 
15
15
  def run
16
- condition_exists? ? handle_conditions : main_value_check
16
+ if_exists? ? handle_if : main_value_check
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def condition_exists?
21
+ def if_exists?
22
22
  !params['if'].nil?
23
23
  end
24
24
 
25
- def handle_conditions
26
- field_name = params['if'].keys.first
27
- condition_hash = params['if'][field_name]
28
- case condition_hash.keys.first
29
- when 'value'
30
- if(data_hash[field_name] == condition_hash.values.first)
31
- main_value_check
32
- end
33
- end
25
+ def handle_if
26
+ main_value_check if pass_if?(params['if'], data_hash)
34
27
  end
35
28
 
36
29
  def main_value_check
@@ -43,9 +36,9 @@ module AeEasy
43
36
  elsif params['regex']
44
37
  add_errored_item(data_hash, field_to_validate, 'value') if (data_hash[field_to_validate].to_s !~ Regexp.new(params['regex'], true))
45
38
  elsif params['less_than']
46
- add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate] < params['less_than'])
39
+ add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate].to_i < params['less_than'].to_i)
47
40
  elsif params['greater_than']
48
- add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate] > params['greater_than'])
41
+ add_errored_item(data_hash, field_to_validate, 'value') if !(data_hash[field_to_validate].to_i > params['greater_than'].to_i)
49
42
  else
50
43
  unknown_value_error
51
44
  end
@@ -1,5 +1,5 @@
1
1
  module AeEasy
2
2
  module Qa
3
- VERSION = "0.0.28"
3
+ VERSION = "0.0.33"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_easy-qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lynam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-19 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: answersengine
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.7.8
111
+ rubygems_version: 2.4.5
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: AnswersEngine Easy Quality Assurance gem