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.
41 42 43 44 |
# File 'lib/oddb2xml/semantic_check.rb', line 41 def initialize(filename) @filename = filename @stammdaten = SemanticCheckXML.new(filename) end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
40 41 42 |
# File 'lib/oddb2xml/semantic_check.rb', line 40 def items @items end |
#limitations ⇒ Object
Returns the value of attribute limitations.
40 41 42 |
# File 'lib/oddb2xml/semantic_check.rb', line 40 def limitations @limitations end |
#products ⇒ Object
Returns the value of attribute products.
40 41 42 |
# File 'lib/oddb2xml/semantic_check.rb', line 40 def products @products end |
Instance Method Details
#allSemanticChecks ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/oddb2xml/semantic_check.rb', line 117 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" unless everyProductNumberIsUnique && everyGTINIsUnique && everyGTINIsNumericOnly && everyPharmaArticleHasAProductItem && everyProductHasAtLeastOneArticle && everyReferencedLimitationIsIncluded && checkPackageSize puts "#{Time.now.strftime("%H:%M:%S")}: Checking #{@stammdaten.filename} failed" false else puts "#{Time.now.strftime("%H:%M:%S")}: Everything is okay" true end rescue => error puts "Execution failed with #{error}" raise error end |
#checkPackageSize ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/oddb2xml/semantic_check.rb', line 107 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
58 59 60 61 62 63 64 65 66 |
# File 'lib/oddb2xml/semantic_check.rb', line 58 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
52 53 54 55 56 |
# File 'lib/oddb2xml/semantic_check.rb', line 52 def everyGTINIsUnique puts "#{Time.now.strftime("%H:%M:%S")}: everyGTINIsUnique" return false unless items.size > 0 return items.collect{ |x| x[:GTIN]}.uniq.size == items.size end |
#everyPharmaArticleHasAProductItem ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/oddb2xml/semantic_check.rb', line 68 def everyPharmaArticleHasAProductItem result = true puts "#{Time.now.strftime("%H:%M:%S")}: everyPharmaArticleHasAProductItem" allProductNumbers = products.collect{ |product| product[:PRODNO] } items.each do |item| next unless item[:PRODNO] unless allProductNumbers.index(item[:PRODNO]) puts "Item #{item[:GTIN]} has no Product #{item[:PRODNO]} #{item[:DSCR]}" result = false end end result end |
#everyProductHasAtLeastOneArticle ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/oddb2xml/semantic_check.rb', line 82 def everyProductHasAtLeastOneArticle result = true puts "#{Time.now.strftime("%H:%M:%S")}: veryProductHasAtLeastOneArticle" allProductNumbers = items.collect{ |item| item[:PRODNO] } products.each do |product| unless allProductNumbers.index(product[:PRODNO]) puts "product #{product[:PRODNO]}: has no Item #{product[:DSCR]}" result = false end end result end |
#everyProductNumberIsUnique ⇒ Object
46 47 48 49 50 |
# File 'lib/oddb2xml/semantic_check.rb', line 46 def everyProductNumberIsUnique puts "#{Time.now.strftime("%H:%M:%S")}: everyProductNumberIsUnique" return false unless products.size > 0 return products.collect{ |x| x[:PRODNO]}.uniq.size == products.size end |
#everyReferencedLimitationIsIncluded ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/oddb2xml/semantic_check.rb', line 95 def everyReferencedLimitationIsIncluded puts "#{Time.now.strftime("%H:%M:%S")}: everyReferencedLimitationIsIncluded" allLimitations = limitations.collect{ |lim| lim[:LIMNAMEBAG] } products.each do |product| next unless product[:LIMNAMEBAG] unless allLimitations.index(product[:LIMNAMEBAG]) puts "product #{product[:PRODNO]} has no limitation #{product[:LIMNAMEBAG]} #{product[:DSCR]}" return false end end end |