class Oddb2xml::SemanticCheck
Attributes
items[RW]
limitations[RW]
products[RW]
Public Class Methods
new(filename)
click to toggle source
# File lib/oddb2xml/semantic_check.rb, line 45 def initialize(filename) @filename = filename @stammdaten = SemanticCheckXML.new(filename) end
Public Instance Methods
allSemanticChecks()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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