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.
55 56 57 58 |
# File 'lib/oddb2xml/semantic_check.rb', line 55 def initialize(filename) @filename = filename @stammdaten = SemanticCheckXML.new(filename) end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
54 55 56 |
# File 'lib/oddb2xml/semantic_check.rb', line 54 def items @items end |
#limitations ⇒ Object
Returns the value of attribute limitations.
54 55 56 |
# File 'lib/oddb2xml/semantic_check.rb', line 54 def limitations @limitations end |
#products ⇒ Object
Returns the value of attribute products.
54 55 56 |
# File 'lib/oddb2xml/semantic_check.rb', line 54 def products @products end |
Instance Method Details
#allSemanticChecks ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/oddb2xml/semantic_check.rb', line 135 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
125 126 127 128 129 130 131 132 133 |
# File 'lib/oddb2xml/semantic_check.rb', line 125 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
72 73 74 75 76 77 78 79 80 |
# File 'lib/oddb2xml/semantic_check.rb', line 72 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
66 67 68 69 70 |
# File 'lib/oddb2xml/semantic_check.rb', line 66 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/oddb2xml/semantic_check.rb', line 82 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
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/oddb2xml/semantic_check.rb', line 98 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
60 61 62 63 64 |
# File 'lib/oddb2xml/semantic_check.rb', line 60 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
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/oddb2xml/semantic_check.rb', line 111 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 |