oddb2xml 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 1.6.6 / 12.12.2013
2
+
3
+ * Added spec for generating *.dat file
4
+ * Output prices in *.dat for articles without a pharmacode
5
+
1
6
  === 1.6.5 / 11.12.2013
2
7
 
3
8
  * Create data/download only if options[:skip_download]
@@ -395,7 +395,7 @@ module Oddb2xml
395
395
  xml.GTIN ean
396
396
  ppac = ((_ppac = @packs[ean[4..11].intern] and !_ppac[:is_tier]) ? _ppac : {})
397
397
  unless ppac
398
- ppac = @packs.find{|pac| pac.ean == ean }.first
398
+ ppac = @packs.find{|pac| pac.ean == ean }.first
399
399
  end
400
400
  xml.PRODNO ppac[:prodno] if ppac[:prodno] and !ppac[:prodno].empty?
401
401
  if seq
@@ -958,19 +958,26 @@ module Oddb2xml
958
958
  rows = []
959
959
  @articles.each do |obj|
960
960
  obj[:de].each_with_index do |idx, i|
961
- next if ((idx[:ean].to_s.length != 13) and !ean14)
961
+ ean = idx[:ean]
962
+ next if ((ean.to_s.length != 13) and !ean14)
962
963
  row = ''
963
964
  # Oddb2tdat.parse
964
965
  if idx[:status] =~ /A|I/
965
966
  pac,no8 = nil,nil
966
967
  if obj[:seq]
967
968
  pac = obj[:seq][:packages][idx[:pharmacode]]
968
- pac = obj[:seq][:packages][idx[:ean]] unless pac
969
+ pac = obj[:seq][:packages][ean] unless pac
970
+ else
971
+ pac = @items[ean][:packages][ean] if @items and @items[ean]
969
972
  end
970
- # :swissmedic_numbers
973
+ # :swissmedic_numbers
971
974
  if pac
972
975
  no8 = pac[:swissmedic_number8].intern
973
976
  end
977
+ if pac and pac[:prices] == nil and no8
978
+ ppac = ((ppac = @packs[no8.intern] and ppac[:is_tier]) ? ppac : nil)
979
+ pac = ppac if ppac
980
+ end
974
981
  row << "%#{DAT_LEN[:RECA]}s" % '11'
975
982
  row << "%#{DAT_LEN[:CMUT]}s" % if (phar = idx[:pharmacode] and phar.size > 3) # does not check expiration_date
976
983
  idx[:status] == "I" ? '3' : '1'
@@ -986,7 +993,7 @@ module Oddb2xml
986
993
  row << format_name(abez)
987
994
  row << "%#{DAT_LEN[:PRMO]}s" % (pac ? format_price(pac[:prices][:exf_price][:price].to_s) : ('0' * DAT_LEN[:PRMO]))
988
995
  row << "%#{DAT_LEN[:PRPU]}s" % (pac ? format_price(pac[:prices][:pub_price][:price].to_s) : ('0' * DAT_LEN[:PRPU]))
989
- row << "%#{DAT_LEN[:CKZL]}s" % if (@lppvs[idx[:ean]])
996
+ row << "%#{DAT_LEN[:CKZL]}s" % if (@lppvs[ean])
990
997
  '2'
991
998
  elsif pac # sl_entry
992
999
  '1'
@@ -1000,7 +1007,7 @@ module Oddb2xml
1000
1007
  '0'
1001
1008
  end
1002
1009
  row << "%#{DAT_LEN[:CBGG]}s" % if ((pac && pac[:narcosis_flag] == 'Y') or # BAGXml
1003
- (@flags[idx[:ean]])) # ywesee BM_update
1010
+ (@flags[ean])) # ywesee BM_update
1004
1011
  '3'
1005
1012
  else
1006
1013
  '0'
@@ -1015,7 +1022,7 @@ module Oddb2xml
1015
1022
  else
1016
1023
  ('0' * DAT_LEN[:ITHE])
1017
1024
  end.to_i
1018
- row << "%0#{DAT_LEN[:CEAN]}d" % idx[:ean].to_i
1025
+ row << "%0#{DAT_LEN[:CEAN]}d" % ean.to_i
1019
1026
  row << "%#{DAT_LEN[:CMWS]}s" % '2' # pharma
1020
1027
  rows << row
1021
1028
  end
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.6.5"
2
+ VERSION = "1.6.6"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -59,12 +59,12 @@ describe Oddb2xml::Builder do
59
59
  article_xml.should match(/<SMNO>53662013</)
60
60
  article_xml.should match(/<DSCRD>3TC Filmtabl 150 mg</)
61
61
  article_xml.should match(/<COMPNO>7601001392175</)
62
- article_xml.should match(/<BC>7680536620137</)
63
- article_xml.should match(/<VDAT>01.10.2011</)
64
- article_xml.should match(/<PTYP>PEXF</)
65
- article_xml.should match(/<PRICE>164.55</)
66
- article_xml.should match(/<PTYP>PPUB</)
67
- article_xml.should match(/<PRICE>205.3</)
62
+ article_xml.should match(/<BC>7680536620137</)
63
+ article_xml.should match(/<VDAT>01.10.2011</)
64
+ article_xml.should match(/<PTYP>PEXF</)
65
+ article_xml.should match(/<PRICE>164.55</)
66
+ article_xml.should match(/<PTYP>PPUB</)
67
+ article_xml.should match(/<PRICE>205.3</)
68
68
 
69
69
  article_xml.should match(/Levetiracetam DESITIN/i) #
70
70
  article_xml.should match(/7680536620137/) # Pharmacode
@@ -79,5 +79,25 @@ describe Oddb2xml::Builder do
79
79
  article_xml.should match(/<COMPNO>7601001320451</)
80
80
  end
81
81
  end
82
+
83
+ context 'when -a nonpharma -f dat is given' do
84
+ let(:cli) do
85
+ opts = {
86
+ :nonpharma => 'true',
87
+ :format => :dat,
88
+ }
89
+ Oddb2xml::Cli.new(opts)
90
+ end
91
+ it 'should generate a valid oddb_with_migel.dat' do
92
+ res = capture(:stdout){ cli.run }
93
+ res.should match(/products/)
94
+ dat_filename = File.expand_path(File.join(File.dirname(__FILE__), '..', 'oddb_with_migel.dat'))
95
+ File.exists?(dat_filename).should be_true
96
+ oddb_dat = IO.read(dat_filename)
97
+ # $stdout.puts oddb_dat
98
+ # return
99
+ oddb_dat.should match(/1115819012LEVETIRACETAM DESITIN Filmtabl 250 mg 30 Stk 001349002780100B010710076806206900842/)
100
+ end
101
+ end
82
102
  end
83
103
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.5
4
+ version: 1.6.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-11 00:00:00.000000000 Z
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip