Class: Oddb2xml::MigelExtractor

Inherits:
Extractor show all
Defined in:
lib/oddb2xml/extractor.rb

Instance Attribute Summary

Attributes inherited from Extractor

#xml

Instance Method Summary collapse

Methods inherited from Extractor

#correct_code

Constructor Details

#initialize(bin) ⇒ MigelExtractor

Returns a new instance of MigelExtractor.



320
321
322
323
324
# File 'lib/oddb2xml/extractor.rb', line 320

def initialize(bin)
  io = StringIO.new(bin)
  book = Spreadsheet.open(io, 'rb')
  @sheet = book.worksheet(0)
end

Instance Method Details

#to_hashObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/oddb2xml/extractor.rb', line 325

def to_hash
  data = {}
  @sheet.each_with_index do |row, i|
    next if i.zero?
    phar = correct_code(row[1].to_s.gsub(/[^0-9]/, ''), 7)
    data[phar] = {
      :refdata         => true,
      :ean             => row[0].to_i.to_s,
      :pharmacode      => phar,
      :desc_de         => row[3],
      :desc_fr         => row[4],
      :additional_desc => row[5], # quantity
      :company_name    => row[6],
      :company_ean     => row[7].to_i.to_s,
    }
  end
  data
end