lib/oddb2xml/util.rb in oddb2xml-2.1.3 vs lib/oddb2xml/util.rb in oddb2xml-2.1.4

- old
+ new

@@ -1,5 +1,6 @@ +require 'open-uri' module Oddb2xml def Oddb2xml.calc_checksum(str) str = str.strip sum = 0 val = str.split(//u) @@ -13,9 +14,24 @@ unless defined?(RSpec) WorkDir = Dir.pwd Downloads = "#{Dir.pwd}/downloads" end @options = {} + @atc_csv_origin = 'https://raw.githubusercontent.com/epha/robot/master/data/manual/swissmedic/atc.csv' + @atc_csv_content = {} + + def Oddb2xml.add_epha_changes_for_ATC(iksnr, atc_code) + if @atc_csv_content.size == 0 + open(@atc_csv_origin).readlines.each{ + |line| + items = line.split(',') + @atc_csv_content[[items[0], items[1]]] = items[2] + } + + end + new_value = @atc_csv_content[[iksnr.to_s, atc_code]] + new_value ? new_value : atc_code + end def Oddb2xml.log(msg) return unless @options[:log] $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}: #{msg}" $stdout.flush