Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. class QC_1812 < Scripting::QCX
  2. NO_DATA = '-'
  3. NA = 'n/a'
  4. EMPTY_VALUES = [nil, '', NO_DATA, NA, 0, '0'].to_set
  5. ALL = 'all'
  6. AMAZON_CORE = [6432].freeze
  7. AMAZON = [6432, 2128].freeze
  8. CHARACTERS = 80
  9. IGNORE_REGEXP = /([[:space:]]*[.\-–—©®™]+[[:space:]]*)/.freeze
  10. BULLETS_SEPARATOR = '@@@@'
  11. COMPARING_PROC = proc { |ev, av| contains_ignore_regexp?(find: ev, inside: av, ignore_regexp: IGNORE_REGEXP, ignore_case: true) }
  12. ADDITIONAL_AV = ['cq_product_description']
  13.  
  14. def props
  15. %q`
  16. Feature #1 /// bullets({ highlight_type: 'bullets'}) /// patch_bullets(1, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
  17. /// patch_bullets(1, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
  18. Feature #2 /// bullets_qc1({ highlight_type: 'bullets'}) /// patch_bullets(2, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
  19. /// patch_bullets(2, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
  20. Feature #3 /// bullets_qc2({ highlight_type: 'bullets'}) /// patch_bullets(3, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
  21. /// patch_bullets(3, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
  22. Feature #4 /// bullets_qc3({ highlight_type: 'bullets'}) /// patch_bullets(4, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
  23. /// patch_bullets(4, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
  24. Feature #5 /// bullets_qc4({ highlight_type: 'bullets'}) /// patch_bullets(5, et_field: "cq_features", hide: true) /// { filter_shops: all_except(/amazon/) }
  25. /// patch_bullets(5, et_field: "cq_bullets", hide: true) /// { filter_shops: /amazon/ }
  26. `
  27. end
  28.  
  29. def compare(_etalon, _product, result)
  30. result
  31. end
  32.  
  33. private
  34.  
  35. def patch_bullets(etalon, product, bullet_index, et_field:, additional_av: ADDITIONAL_AV, hide: false, comparing_proc: COMPARING_PROC)
  36. # comparing_proc ||= proc { |ev, av| contains_ignore_regexp?(find: ev, inside: av, ignore_regexp: IGNORE_REGEXP, ignore_case: true) }
  37. # additional_av ||= ['cq_product_description']
  38. fields_count = fields_count()
  39.  
  40. unless @match_shared_data[bullet_index]
  41. et_bullets = (etalon.get(et_field) || '').split(BULLETS_SEPARATOR).first(fields_count)
  42. actual_bullets = (product.get('cq_bullets') || '').split(BULLETS_SEPARATOR)
  43. text_to_search = actual_bullets.join
  44. additional_av.each do |field|
  45. text_to_search += product.get(field) || ''
  46. end
  47. if text_to_search.empty? # AV-
  48. (1..fields_count).each do |bullet_number|
  49. et_bullet = et_bullets[bullet_number - 1]
  50. @match_shared_data[bullet_number] =
  51. if et_bullet # EV+AV-
  52. [{ et_val: et_bullet, prod_val: NO_DATA }, false]
  53. else # EV-AV-
  54. hide ? NO_DECISION : [{ et_val: NA, prod_val: NO_DATA }, false]
  55. end
  56. end
  57. else
  58. unmatched_etalon_bullets = (1..fields_count).to_a.delete_if do |bullet_number|
  59. et_bullet = et_bullets[bullet_number - 1]
  60. match_found = false
  61. if et_bullet
  62. actual_bullets.delete_if do |actual_bullet| # find in actual_bullets
  63. match_found = comparing_proc.call(et_bullet, actual_bullet)
  64. @match_shared_data[bullet_number] = [{ et_val: et_bullet, prod_val: match_found }, true] if match_found
  65. match_found
  66. end
  67. unless match_found # find in text_to_search
  68. match_found = comparing_proc.call(et_bullet, text_to_search)
  69. @match_shared_data[bullet_number] = [{ et_val: et_bullet, prod_val: match_found }, true] if match_found
  70. end
  71. end
  72. match_found
  73. end
  74. unmatched_etalon_bullets.each do |bullet_number|
  75. et_bullet = et_bullets[bullet_number - 1]
  76. unmatched_actual_bullet = actual_bullets.shift
  77. @match_shared_data[bullet_number] =
  78. if unmatched_actual_bullet
  79. [{ et_val: et_bullet || NA, prod_val: unmatched_actual_bullet }, !et_bullet]
  80. else # EV- and no AV bullet
  81. hide ? NO_DECISION : [{ et_val: et_bullet || NA, prod_val: NO_DATA }, !et_bullet]
  82. end
  83. end
  84. end
  85. end
  86. @match_shared_data[bullet_index]
  87. end
  88.  
  89. def fields_count
  90. bullets_props = props.split(/\n/)[1..-1].map do |prop|
  91. prop[%r{(.*)///.*///\s+patch_bullets}, 1]
  92. end
  93. bullets_props.compact!.last[/\d+/].to_i
  94. end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement