class Oddb2xml::ZurroseExtractor
Public Class Methods
new(dat, extended = false, artikelstamm = false)
click to toggle source
see dev.ywesee.com/Bbmb/TransferDat
# File lib/oddb2xml/extractor.rb, line 493 def initialize(dat, extended = false, artikelstamm = false) @@extended = extended @artikelstamm = artikelstamm FileUtils.makedirs(WORK_DIR) @@error_file ||= File.open(File.join(WORK_DIR, "duplicate_ean13_from_zur_rose.txt"), "wb+:ISO-8859-14") @@items_without_ean13s ||= 0 @@duplicated_ean13s ||= 0 @@zur_rose_items ||= 0 if dat @io = if File.exist?(dat) File.open(dat, "rb:ISO-8859-14") else StringIO.new(dat) end @io end end
Public Instance Methods
to_hash()
click to toggle source
# File lib/oddb2xml/extractor.rb, line 511 def to_hash data = {} if @io while (line = @io.gets) ean13 = "-1" line = Oddb2xml.patch_some_utf8(line).chomp # next unless /(7680\d{9})(\d{1})$/.match(line) # Skip non pharma next if /(ad us\.* vet)|(\(vet\))/i.match?(line) if @@extended next unless (match_data = line.match(/(\d{13})(\d{1})$/)) else next unless (match_data = line.match(/(7680\d{9})(\d{1})$/)) end pharma_code = line[3..9] if match_data[1].to_s == "0000000000000" @@items_without_ean13s += 1 next if @artikelstamm && pharma_code.to_i == 0 ean13 = Oddb2xml::FAKE_GTIN_START + pharma_code.to_s unless @artikelstamm else ean13 = match_data[1] end if data[ean13] @@error_file.puts "Duplicate ean13 #{ean13} in line \nact: #{line.chomp}\norg: #{data[ean13][:line]}" @@items_without_ean13s -= 1 @@duplicated_ean13s += 1 next end pexf = sprintf("%.2f", line[60, 6].gsub(/(\d{2})$/, '.\1').to_f) ppub = sprintf("%.2f", line[66, 6].gsub(/(\d{2})$/, '.\1').to_f) next if @artikelstamm && /^113/.match(line) && ppub.eql?("0.0") && pexf.eql?("0.0") next unless ean13 key = ean13 key = (Oddb2xml::FAKE_GTIN_START + pharma_code.to_s) if ean13.to_i <= 0 # dummy ean13 data[key] = { data_origin: "zur_rose", line: line.chomp, ean13: ean13, clag: line[73], vat: line[96], description: line[10..59].sub(/\s+$/, ""), quantity: "", pharmacode: pharma_code, price: pexf, pub_price: ppub, type: :nonpharma, cmut: line[2] } @@zur_rose_items += 1 end end if defined?(@@extended) && @@extended @@error_file.puts get_error_msg end @@error_file.close @@error_file = nil data end
Private Instance Methods
get_error_msg()
click to toggle source
# File lib/oddb2xml/extractor.rb, line 577 def get_error_msg if defined?(@@extended) && @@extended msg = "Added #{@@items_without_ean13s} via pharmacodes of #{@@zur_rose_items} items when extracting the transfer.dat from \"Zur Rose\"" msg += "\n found #{@@duplicated_ean13s} lines with duplicated ean13" if @@duplicated_ean13s > 0 return msg end nil end