Class: Oddb2xml::SemanticCheck
- Inherits:
-
Object
- Object
- Oddb2xml::SemanticCheck
- Defined in:
- lib/oddb2xml/semantic_check.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#limitations ⇒ Object
Returns the value of attribute limitations.
-
#products ⇒ Object
Returns the value of attribute products.
Instance Method Summary collapse
- #allSemanticChecks ⇒ Object
- #checkPackageSize ⇒ Object
- #everyGTINIsNumericOnly ⇒ Object
- #everyGTINIsUnique ⇒ Object
- #everyPharmaArticleHasAProductItem ⇒ Object
- #everyProductHasAtLeastOneArticle ⇒ Object
- #everyProductNumberIsUnique ⇒ Object
- #everyReferencedLimitationIsIncluded ⇒ Object
-
#initialize(filename) ⇒ SemanticCheck
constructor
A new instance of SemanticCheck.
Constructor Details
#initialize(filename) ⇒ SemanticCheck
Returns a new instance of SemanticCheck.
45 46 47 48 |
# File 'lib/oddb2xml/semantic_check.rb', line 45 def initialize(filename) @filename = filename @stammdaten = SemanticCheckXML.new(filename) end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
44 45 46 |
# File 'lib/oddb2xml/semantic_check.rb', line 44 def items @items end |
#limitations ⇒ Object
Returns the value of attribute limitations.
44 45 46 |
# File 'lib/oddb2xml/semantic_check.rb', line 44 def limitations @limitations end |
#products ⇒ Object
Returns the value of attribute products.
44 45 46 |
# File 'lib/oddb2xml/semantic_check.rb', line 44 def products @products end |
Instance Method Details
#allSemanticChecks ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/oddb2xml/semantic_check.rb', line 125 def allSemanticChecks @limitations = @stammdaten.get_items("LIMITATIONS") @items = @stammdaten.get_items("ITEMS") @products = @stammdaten.get_items("PRODUCTS") puts "#{Time.now.strftime("%H:%M:%S")}: Running all semantic checks for #{@stammdaten.filename} for #{products.size} products and #{items.size} items" if everyProductNumberIsUnique && everyGTINIsUnique && everyGTINIsNumericOnly && everyPharmaArticleHasAProductItem && everyProductHasAtLeastOneArticle && everyReferencedLimitationIsIncluded && checkPackageSize puts "#{Time.now.strftime("%H:%M:%S")}: Everything is okay" true else puts "#{Time.now.strftime("%H:%M:%S")}: Checking #{@stammdaten.filename} failed" false end rescue => error puts "Execution failed with #{error}" raise error end |
#checkPackageSize ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/oddb2xml/semantic_check.rb', line 115 def checkPackageSize puts "#{Time.now.strftime("%H:%M:%S")}: checkPackageSize" items.each do |item| if item["PKG_SIZE"] && item["PKG_SIZE"].length >= 6 puts "WARNING possibly invalid package size #{item["PKG_SIZE"]}" pp item end end end |
#everyGTINIsNumericOnly ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/oddb2xml/semantic_check.rb', line 62 def everyGTINIsNumericOnly puts "#{Time.now.strftime("%H:%M:%S")}: everyGTINIsNumericOnly" items.each do |item| unless /^[0-9]+$/i.match?(item[:GTIN]) puts "GTIN is not Numeric Only" return false end end end |
#everyGTINIsUnique ⇒ Object
56 57 58 59 60 |
# File 'lib/oddb2xml/semantic_check.rb', line 56 def everyGTINIsUnique puts "#{Time.now.strftime("%H:%M:%S")}: everyGTINIsUnique" return false unless items.size > 0 items.collect { |x| x[:GTIN] }.uniq.size == items.size end |
#everyPharmaArticleHasAProductItem ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/oddb2xml/semantic_check.rb', line 72 def everyPharmaArticleHasAProductItem result = true puts "#{Time.now.strftime("%H:%M:%S")}: everyPharmaArticleHasAProductItem" all_product_numbers = products.collect { |product| product[:PRODNO] } items.each do |item| next unless item[:PRODNO] unless item[:Chapter70_HACK] unless all_product_numbers.index(item[:PRODNO]) puts "Item #{item[:GTIN]} has no Product #{item[:PRODNO]} #{item[:DSCR]}" result = false end end end result end |
#everyProductHasAtLeastOneArticle ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/oddb2xml/semantic_check.rb', line 88 def everyProductHasAtLeastOneArticle result = true puts "#{Time.now.strftime("%H:%M:%S")}: veryProductHasAtLeastOneArticle" all_product_numbers = items.collect { |item| item[:PRODNO] } products.each do |product| unless all_product_numbers.index(product[:PRODNO]) puts "product #{product[:PRODNO]}: has no Item #{product[:DSCR]}" result = false end end result end |
#everyProductNumberIsUnique ⇒ Object
50 51 52 53 54 |
# File 'lib/oddb2xml/semantic_check.rb', line 50 def everyProductNumberIsUnique puts "#{Time.now.strftime("%H:%M:%S")}: everyProductNumberIsUnique" return false unless products.size > 0 products.collect { |x| x[:PRODNO] }.uniq.size == products.size end |
#everyReferencedLimitationIsIncluded ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/oddb2xml/semantic_check.rb', line 101 def everyReferencedLimitationIsIncluded result = true puts "#{Time.now.strftime("%H:%M:%S")}: everyReferencedLimitationIsIncluded" all_limitations = limitations.collect { |lim| lim[:LIMNAMEBAG] } products.each do |product| next unless product[:LIMNAMEBAG] unless all_limitations.index(product[:LIMNAMEBAG]) puts "product #{product[:PRODNO]} has no limitation #{product[:LIMNAMEBAG]} #{product[:DSCR]}" result = false end end result end |