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

Constructor Details

#initialize(bin) ⇒ MigelExtractor

Returns a new instance of MigelExtractor.



313
314
315
316
317
# File 'lib/oddb2xml/extractor.rb', line 313

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

Instance Method Details

#to_hashObject



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/oddb2xml/extractor.rb', line 318

def to_hash
  data = {}
  @sheet.each_with_index do |row, i|
    next if i.zero?
    phar = row[1].to_i
    ean = row[0].to_i
    ean = phar unless ean.to_s.length == 13
    data[ean] = {
      :refdata         => true,
      :ean             => ean,
      :pharmacode      => phar.to_i,
      :desc_de         => row[3],
      :desc_fr         => row[4],
      :quantity        => row[5], # quantity
      :company_name    => row[6],
      :company_ean     => row[7].to_i,
    }
  end
  data
end