Module: ODDB::Import::Dimdi
- Defined in:
- lib/oddb/import/dimdi.rb
Defined Under Namespace
Classes: GalenicForm, Product, Substance
Constant Summary
collapse
- DIMDI_PATH =
"http://www.dimdi.de/dynamic/de/amg/fbag/downloadcenter/"
Class Method Summary
collapse
Class Method Details
.current_date(url) ⇒ Object
33
34
35
36
37
|
# File 'lib/oddb/import/dimdi.rb', line 33
def Dimdi.current_date(url)
if(match = /festbetraege-(\d{4})(\d{2})\.xls/.match(open(url).read))
Date.new(match[1].to_i, match[2].to_i)
end
end
|
.download(file, &block) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/oddb/import/dimdi.rb', line 38
def Dimdi.download(file, &block)
url = File.join(download_path, file)
xls_dir = File.join(ODDB.config.var, 'xls')
FileUtils.mkdir_p(xls_dir)
dest = File.join(xls_dir, file)
unless(File.exist?(dest))
open(url) { |remote|
block.call(remote)
remote.rewind
open(dest, 'w') { |local|
local << remote.read
}
}
end
rescue StandardError => e
ODDB.logger.error('Dimdi') { e.message }
end
|
.download_latest(url, today, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/oddb/import/dimdi.rb', line 55
def Dimdi.download_latest(url, today, &block)
file = File.basename(url)
xls_dir = File.join(ODDB.config.var, 'xls')
FileUtils.mkdir_p(xls_dir)
dest = File.join(xls_dir, file)
archive = File.join(ODDB.config.var, 'xls',
sprintf("%s-%s", today.strftime("%Y.%m.%d"), file))
content = open(url).read
if(!File.exist?(dest) || content.size != File.size(dest))
open(archive, 'w') { |local|
local << content
}
open(archive, 'r', &block)
open(dest, 'w') { |local|
local << content
}
end
rescue StandardError => error
ODDB.logger.error('Dimdi') { error.message }
end
|
.download_path ⇒ Object
28
29
30
31
32
|
# File 'lib/oddb/import/dimdi.rb', line 28
def Dimdi.download_path
quater = ((Time.now.month-1)/3+1).to_s
year = Time.now.year.to_s
return DIMDI_PATH + year + "/" + quater + "-quartal/"
end
|