def to_hash
data = {}
if @io
while (line = @io.gets)
ean13 = "-1"
line = Oddb2xml.patch_some_utf8(line).chomp
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
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