Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class QC_1812 < Scripting::QCX
- NO_DATA = '-'
- NA = 'n/a'
- EMPTY_VALUES = [nil, '', NO_DATA, NA, 0, '0'].to_set
- ALL = 'all'
- AMAZON_CORE = [6432].freeze
- AMAZON = [6432, 2128].freeze
- CHARACTERS = 80
- IGNORE_REGEXP = /([[:space:]]*[.\-–—©®™]+[[:space:]]*)/.freeze
- BULLETS_SEPARATOR = '@@@@'
- COMPARING_PROC = proc { |ev, av| contains_ignore_regexp?(find: ev, inside: av, ignore_regexp: IGNORE_REGEXP, ignore_case: true) }
- ADDITIONAL_AV = ['cq_product_description']
- def props
- %q`
- Feature #1 /// bullets({ highlight_type: 'bullets'}) /// patch_bullets(1, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
- /// patch_bullets(1, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
- Feature #2 /// bullets_qc1({ highlight_type: 'bullets'}) /// patch_bullets(2, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
- /// patch_bullets(2, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
- Feature #3 /// bullets_qc2({ highlight_type: 'bullets'}) /// patch_bullets(3, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
- /// patch_bullets(3, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
- Feature #4 /// bullets_qc3({ highlight_type: 'bullets'}) /// patch_bullets(4, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
- /// patch_bullets(4, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
- Feature #5 /// bullets_qc4({ highlight_type: 'bullets'}) /// patch_bullets(5, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
- /// patch_bullets(5, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
- `
- end
- def compare(_etalon, _product, result)
- result
- end
- private
- def patch_bullets(etalon, product, bullet_index, et_field:, additional_av: ADDITIONAL_AV, hide: false, comparing_proc: COMPARING_PROC)
- # comparing_proc ||= proc { |ev, av| contains_ignore_regexp?(find: ev, inside: av, ignore_regexp: IGNORE_REGEXP, ignore_case: true) }
- # additional_av ||= ['cq_product_description']
- fields_count = fields_count()
- unless @match_shared_data[bullet_index]
- et_bullets = (etalon.get(et_field) || '').split(BULLETS_SEPARATOR).first(fields_count)
- actual_bullets = (product.get('cq_bullets') || '').split(BULLETS_SEPARATOR)
- text_to_search = actual_bullets.join
- additional_av.each do |field|
- text_to_search += product.get(field) || ''
- end
- if text_to_search.empty? # AV-
- (1..fields_count).each do |bullet_number|
- et_bullet = et_bullets[bullet_number - 1]
- @match_shared_data[bullet_number] =
- if et_bullet # EV+AV-
- [{ et_val: et_bullet, prod_val: NO_DATA }, false]
- else # EV-AV-
- hide ? NO_DECISION : [{ et_val: NA, prod_val: NO_DATA }, false]
- end
- end
- else
- unmatched_etalon_bullets = (1..fields_count).to_a.delete_if do |bullet_number|
- et_bullet = et_bullets[bullet_number - 1]
- match_found = false
- if et_bullet
- actual_bullets.delete_if do |actual_bullet| # find in actual_bullets
- match_found = comparing_proc.call(et_bullet, actual_bullet)
- @match_shared_data[bullet_number] = [{ et_val: et_bullet, prod_val: match_found }, true] if match_found
- match_found
- end
- unless match_found # find in text_to_search
- match_found = comparing_proc.call(et_bullet, text_to_search)
- @match_shared_data[bullet_number] = [{ et_val: et_bullet, prod_val: match_found }, true] if match_found
- end
- end
- match_found
- end
- unmatched_etalon_bullets.each do |bullet_number|
- et_bullet = et_bullets[bullet_number - 1]
- unmatched_actual_bullet = actual_bullets.shift
- @match_shared_data[bullet_number] =
- if unmatched_actual_bullet
- [{ et_val: et_bullet || NA, prod_val: unmatched_actual_bullet }, !et_bullet]
- else # EV- and no AV bullet
- hide ? NO_DECISION : [{ et_val: et_bullet || NA, prod_val: NO_DATA }, !et_bullet]
- end
- end
- end
- end
- @match_shared_data[bullet_index]
- end
- def fields_count
- bullets_props = props.split(/\n/)[1..-1].map do |prop|
- prop[%r{(.*)///.*///\s+patch_bullets}, 1]
- end
- bullets_props.compact!.last[/\d+/].to_i
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement