Class: Oddb2xml::RefdataExtractor
- Defined in:
- lib/oddb2xml/extractor.rb
Instance Attribute Summary
Attributes inherited from Extractor
Instance Method Summary collapse
-
#initialize(xml, type) ⇒ RefdataExtractor
constructor
A new instance of RefdataExtractor.
- #to_hash ⇒ Object
Constructor Details
#initialize(xml, type) ⇒ RefdataExtractor
Returns a new instance of RefdataExtractor.
170 171 172 173 |
# File 'lib/oddb2xml/extractor.rb', line 170 def initialize(xml, type) @type = (type == :pharma ? 'PHARMA' : 'NONPHARMA') super(xml) end |
Instance Method Details
#to_hash ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/oddb2xml/extractor.rb', line 174 def to_hash data = {} result = SwissRegArticleEntry.parse(@xml.sub(Strip_For_Sax_Machine, ''), :lazy => true) items = result.ARTICLE.ITEM items.each do |pac| item = {} item[:refdata] = true item[:_type] = (typ = pac.ATYPE.downcase.to_sym) ? typ: '' item[:ean] = (gtin = pac.GTIN.to_i) ? gtin: 0 item[:pharmacode] = (phar = pac.PHAR.to_i) ? phar: 0 item[:last_change] = (date = Time.parse(pac.DT).to_s) ? date: '' # Date and time of last data change item[:desc_de] = (dscr = pac.NAME_DE) ? dscr: '' item[:desc_fr] = (dscr = pac.NAME_FR) ? dscr: '' item[:atc_code] = (code = pac.ATC) ? code.to_s : '' item[:company_name] = (nam = pac.AUTH_HOLDER_NAME) ? nam: '' item[:company_ean] = (gln = pac.AUTH_HOLDER_GLN) ? gln: '' unless item[:pharmacode] item[:pharmacode] = phar unless data[item[:pharmacode]] # pharmacode => GTINs data[item[:ean]] = [] end end data[item[:ean]] = item end data end |