Class: Oddb2xml::SwissmedicExtractor

Inherits:
Extractor
  • Object
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, type) ⇒ SwissmedicExtractor



198
199
200
201
202
203
# File 'lib/oddb2xml/extractor.rb', line 198

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

Instance Method Details

#to_arryObject



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/oddb2xml/extractor.rb', line 204

def to_arry
  data = []
  case @type
  when :orphan
    i = 1
    @sheet.each do |row|
      if number = extract_number(row, i)
        data << number.to_s
      end
    end
  when :fridge
    i,c = 1,7
    @sheet.each do |row|
      if number = extract_number(row, i) and row[c] and row[c].to_s == 'x'
        data << row[i].to_s
      end
    end
  end
  data.uniq
end

#to_hashObject

Packungen.xls



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/oddb2xml/extractor.rb', line 224

def to_hash # Packungen.xls
  data = {}
  case @type
  when :package
    typ = 6 # Heilmittelcode
    i_5,i_3   = 0,10 # :swissmedic_numbers
    p_5,p_1_2 = 0,1  # :prodno
    cat       = 13   # :swissmedic_category
    ith       = 4    # :ith_swissmedic IT-Code (swissmedic-diff)
    atc       = 5    # :atc_code
    siz       = 11   # :package_size
    eht       = 12   # :einheit_swissmedic
    sub       = 14   # :substance_swissmedic
    @sheet.each_with_index do |row, i|
      next if (i== 0)
      no8 = extract_number(row, i_5).to_s + extract_number(row, i_3, /^\d{3}$/).to_s
      unless no8.empty?
        ean_base12 = "7680#{no8}"
        data[no8.intern] = {
          :ean                  => (ean_base12.ljust(12, '0') + calc_checksum(ean_base12)),
          :prodno               => row[p_5].to_s + row[p_1_2].to_i.to_s,
          :ith_swissmedic       => row[ith].to_s,
          :swissmedic_category  => row[cat].to_s,
          :atc_code             => row[atc].to_s,
          :package_size         => row[siz].to_s,
          :einheit_swissmedic   => row[eht].to_s,
          :substance_swissmedic => row[sub].to_s,
          :is_tier              => (row[typ] == 'Tierarzneimittel' ? true : false),
        }
      end
    end
  end
  data
end