lib/oddb2xml/cli.rb in oddb2xml-2.1.9 vs lib/oddb2xml/cli.rb in oddb2xml-2.2.0

- old
+ new

@@ -88,11 +88,10 @@ report end private def build Oddb2xml.log("Start build") - puts "#{File.basename(__FILE__)}:#{__LINE__}: @refdata_types.keys #{@refdata_types.keys}" begin # require 'pry'; binding.pry @_files = {"calc"=>"oddb_calc.xml"} if @options[:calc] and not @options[:extended] files.each_pair do |sbj, file| builder = Builder.new(@options) do |builder| @@ -161,109 +160,127 @@ when :company, :person var = (what == :company ? 'companies' : 'people') begin # instead of Thread.new do downloader = MedregbmDownloader.new(what) str = downloader.download + Oddb2xml.log("SwissmedicInfoDownloader #{what} str #{str.size} bytes") self.instance_variable_set( "@#{var}".intern, - MedregbmExtractor.new(str, what).to_arry + items = MedregbmExtractor.new(str, what).to_arry ) + Oddb2xml.log("MedregbmExtractor #{what} added #{items.size} fachinfo") + items end when :fachinfo begin # instead of Thread.new do downloader = SwissmedicInfoDownloader.new xml = downloader.download + Oddb2xml.log("SwissmedicInfoDownloader #{var} xml #{xml.size} bytes") @mutex.synchronize do hsh = SwissmedicInfoExtractor.new(xml).to_hash @infos = hsh Oddb2xml.log("SwissmedicInfoExtractor added #{@infos.size} fachinfo") + @infos end end when :orphan, :fridge var = what.to_s + 's' begin # instead of Thread.new do downloader = SwissmedicDownloader.new(what) bin = downloader.download + Oddb2xml.log("SwissmedicDownloader #{var} bin #{bin.size} bytes") self.instance_variable_set( "@#{var}".intern, - SwissmedicExtractor.new(bin, what).to_arry + items = SwissmedicExtractor.new(bin, what).to_arry ) -# Oddb2xml.log("SwissmedicExtractor added #{self.instance_variable_get("@#{var}".intern).size} #{var}. File #{bin} was #{File.size(bin)} bytes") + Oddb2xml.log("SwissmedicExtractor added #{items.size} #{var}. File #{bin} was #{File.size(bin)} bytes") + items end when :interaction begin # instead of Thread.new do downloader = EphaDownloader.new str = downloader.download + Oddb2xml.log("EphaDownloader str #{str.size} bytes") @mutex.synchronize do @actions = EphaExtractor.new(str).to_arry Oddb2xml.log("EphaExtractor added #{@actions.size} interactions") + @actions end end when :migel begin # instead of Thread.new do downloader = MigelDownloader.new bin = downloader.download + Oddb2xml.log("MigelDownloader bin #{bin.size} bytes") @mutex.synchronize do @migel = MigelExtractor.new(bin).to_hash Oddb2xml.log("MigelExtractor added #{@migel.size} migel items") + @migel end end when :package begin # instead of Thread.new do downloader = SwissmedicDownloader.new(:package, @options) bin = downloader.download + Oddb2xml.log("SwissmedicDownloader bin #{bin.size} bytes") @mutex.synchronize do @packs = SwissmedicExtractor.new(bin, :package).to_hash Oddb2xml.log("SwissmedicExtractor added #{@packs.size} packs from #{bin}") @packs end end when :bm_update begin # instead of Thread.new do downloader = BMUpdateDownloader.new str = downloader.download + Oddb2xml.log("BMUpdateDownloader str #{str.size} bytes") @mutex.synchronize do @flags = BMUpdateExtractor.new(str).to_hash Oddb2xml.log("BMUpdateExtractor added #{@flags.size} flags") + @flags end end when :lppv begin # instead of Thread.new do downloader = LppvDownloader.new str = downloader.download + Oddb2xml.log("LppvDownloader str #{str.size} bytes") @mutex.synchronize do @lppvs = LppvExtractor.new(str).to_hash Oddb2xml.log("LppvExtractor added #{@lppvs.size} lppvs") + @lppvs end end when :bag begin # instead of Thread.new do downloader = BagXmlDownloader.new(@options) xml = downloader.download + Oddb2xml.log("BagXmlDownloader xml #{xml.size} bytes") @mutex.synchronize do hsh = BagXmlExtractor.new(xml).to_hash @items = hsh - Oddb2xml.log("BagXmlDownloader added #{@items.size} items. #{@items.keys}") + Oddb2xml.log("BagXmlExtractor added #{@items.size} items.") + @items end end when :zurrose begin # instead of Thread.new do downloader = ZurroseDownloader.new(@options, @options[:transfer_dat]) xml = downloader.download - Oddb2xml.log("zurrose xml #{xml.size} bytes") + Oddb2xml.log("ZurroseDownloader xml #{xml.size} bytes") @mutex.synchronize do hsh = ZurroseExtractor.new(xml, @options[:extended]).to_hash - Oddb2xml.log("zurrose added #{hsh.size} items from xml with #{xml.size} bytes") + Oddb2xml.log("ZurroseExtractor added #{hsh.size} items from xml with #{xml.size} bytes") @infos_zur_rose = hsh end end when :refdata begin # instead of Thread.new do downloader = RefdataDownloader.new(@options, type) begin xml = downloader.download - Oddb2xml.log("refdata #{type} xml #{xml.size} bytes") + Oddb2xml.log("RefdataDownloader #{type} xml #{xml.size} bytes") xml rescue SystemExit @mutex.synchronize do unless @_message # hook only one exit @_message = true @@ -272,11 +289,12 @@ end end @mutex.synchronize do hsh = RefdataExtractor.new(xml, type).to_hash @refdata_types[type] = hsh - Oddb2xml.log("refdata #{type} added #{hsh.size} keys now #{@refdata_types.keys} items from xml with #{xml.size} bytes") + Oddb2xml.log("RefdataExtractor #{type} added #{hsh.size} keys now #{@refdata_types.keys} items from xml with #{xml.size} bytes") + @refdata_types[type] end end end end def compress @@ -330,10 +348,10 @@ unless @options[:address] types.each do |type| if @refdata_types[type] indices = @refdata_types[type].values.flatten.length if type == :nonpharma - migel_xls = @migel.values.compact.select{|m| !m[:pharmacode].empty? }.map{|m| m[:pharmacode] } + migel_xls = @migel.values.compact.select{|m| !m[:pharmacode]}.map{|m| m[:pharmacode] } nonpharmas = @refdata_types[type].keys indices += (migel_xls - nonpharmas).length # ignore duplicates, null lines << sprintf("\tNonPharma products: %i", indices) else lines << sprintf("\tPharma products: %i", indices)