Class: Oddb2xml::SwissIndexExtractor

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(xml, type) ⇒ SwissIndexExtractor

Returns a new instance of SwissIndexExtractor.



182
183
184
185
# File 'lib/oddb2xml/extractor.rb', line 182

def initialize(xml, type)
  @type = (type == :pharma ? 'PHARMA' : 'NONPHARMA')
  super(xml)
end

Instance Method Details

#to_hashObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/oddb2xml/extractor.rb', line 186

def to_hash
  data = {}
  result = PharmaEntry.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true)
  items = result.PHARMA.ITEM
  items.each do |pac|
    item = {}
    item[:refdata]         = true
    item[:_type]           = @type.downcase.intern
    item[:ean]             = (gtin = pac.GTIN)   ? gtin: ''
    item[:pharmacode]      = (phar = pac.PHAR)   ? phar: ''
    item[:stat_date]       = (date = pac.SDATE)  ? date: ''
    item[:lang]            = (lang = pac.LANG)   ? lang: ''
    item[:desc]            = (dscr = pac.DSCR)   ? dscr: ''
    item[:atc_code]        = (code = pac.ATC)    ? code.to_s : ''
    # as quantity text
    item[:additional_desc] = (dscr = pac.ADDSCR) ? dscr: ''
    if comp = pac.COMP
      item[:company_name] = (nam = comp.NAME) ? nam: ''
      item[:company_ean]  = (gln = comp.GLN)  ? gln: ''
    end
    unless item[:pharmacode].empty?
      item[:pharmacode] = correct_code(item[:pharmacode].to_s, 7)
      unless data[item[:pharmacode]] # pharmacode => GTINs
        data[item[:pharmacode]] = []
      end
      data[item[:pharmacode]] << item
    end
  end
  data
end