oddb2tdat 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/History.txt +5 -0
  2. data/lib/oddb2tdat.rb +46 -27
  3. metadata +4 -4
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 1.0.4 / 13.01.2012
2
+
3
+ * Update CMUT, if Gültig bis is before today CMUT = 3
4
+ * Updated RECA, CMUT, PRMO, ITHE format
5
+
1
6
  === 1.0.3 / 12.01.2012
2
7
 
3
8
  * Fix Publikumspreis format. if it is over 6 digits, the last parts will be cut.
data/lib/oddb2tdat.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #! /usr/bin/env ruby
2
2
  # encoding: utf-8
3
- # Oddb2tdat -- 12.01.2012 -- mhatakeyama@ywesee.com
3
+ # Oddb2tdat -- 13.01.2012 -- mhatakeyama@ywesee.com
4
4
 
5
+ require 'date'
5
6
  =begin
6
7
  01 RECA Recordart 001 – 002 2 alpha: 11
7
- 02 CMUT Mutationscode 003 – 003 1 num: 3 ausser Handel (AE) sonst 1
8
+ 02 CMUT Mutationscode 003 – 003 1 num: 3 ausser Handel (AE) sonst 1. If there is no Pharmacode or Gültig bis is before today, CMUT must be 3.
8
9
  03 PHAR Pharmacode 004 – 010 7 num: Pharmacode (G)
9
10
  04 ABEZ Artikelbezeichnung 011 – 060 50 alpha: Präparate (H,K)
10
11
  05 PRMO Arztpreis (=Galexis-Basis-Preis) 061 – 066 6 num: NIL
@@ -21,11 +22,12 @@
21
22
  =end
22
23
 
23
24
  class Oddb2tdat
24
- VERSION = '1.0.3'
25
+ VERSION = '1.0.4'
25
26
  COL = {
26
27
  :CMUT => 30, # AE
27
28
  :PHAR => 6, # G
28
29
  :ABEZ => 7, # H
30
+ :PRMO => 12, # M
29
31
  :PRPU => 13, # N
30
32
  :CKZL1 => 16, # Q
31
33
  :CKZL2 => 21, # V
@@ -34,6 +36,7 @@ class Oddb2tdat
34
36
  :ITHE => 33, # AH
35
37
  :CEAN => 4, # E
36
38
  :PACK => 10, # K
39
+ :GULT => 23, # X
37
40
  }
38
41
  LEN = {
39
42
  :RECA => 2,
@@ -58,38 +61,54 @@ class Oddb2tdat
58
61
  parse
59
62
  output
60
63
  end
64
+ def format_price(price_str, len=6, int_len=4, frac_len=2)
65
+ price = price_str.split('.')
66
+ pre = ''
67
+ las = ''
68
+ pre = "%0#{int_len}d" % (price[0] ? price[0] : '0')
69
+ las = if price[1]
70
+ if price[1].size < frac_len
71
+ price[1] + "0"*(frac_len-price[2].size)
72
+ else
73
+ price[1][0,frac_len]
74
+ end
75
+ else
76
+ '0'*frac_len
77
+ end
78
+ (pre.to_s + las.to_s)[0,len]
79
+ end
80
+ def format_date(date_str, len=7)
81
+ date = date_str.gsub('.','')
82
+ if date.size < len
83
+ date = date + '0'*(len-date.size)
84
+ end
85
+ date[0,len]
86
+ end
87
+ def expired?(date_str)
88
+ d = date_str.split('.')
89
+ if d.length == 3
90
+ d.map!{|i| i.to_i}
91
+ date = Date.new(d[2],d[1],d[0])
92
+ Date.today > date
93
+ end
94
+ end
61
95
  def parse
62
96
  @rows = []
63
97
  File.open(@input, 'r:iso-8859-1:utf-8') do |input|
64
98
  while line=input.gets
65
99
  row = ''
66
- prpu = ''
67
- pre = ''
68
- las = ''
69
100
  cols = line.split(/;/)
70
101
  if cmut = cols[COL[:CMUT]] and cmut =~ /Ja/ or cmut =~ /Nein/
71
- row << "%#{LEN[:RECA]}s" % '11'
72
- row << "%#{LEN[:CMUT]}s" % (cmut =~ /Ja/ ? '3':'1')
102
+ row << "%#{LEN[:RECA]}s" % '01'
103
+ row << "%#{LEN[:CMUT]}s" % if(phar = cols[COL[:PHAR]] and phar.size > 3) or (!expired?(cols[COL[:GULT]]))
104
+ (cmut =~ /Ja/ ? '3':'1')
105
+ else
106
+ '3'
107
+ end
73
108
  row << "%0#{LEN[:PHAR]}d" % cols[COL[:PHAR]].to_i
74
109
  row << "%-#{LEN[:ABEZ]}s" % (cols[COL[:ABEZ]].to_s + " " + cols[COL[:PACK]]).to_s[0,LEN[:ABEZ]]
75
- row << "%0#{LEN[:PRMO]}d" % 0
76
- prpu = cols[COL[:PRPU]].to_s.split('.')
77
- pre = "%04d" % if prpu[0]
78
- prpu[0]
79
- else
80
- 0
81
- end
82
- las = if prpu[1]
83
- if prpu[1].size < 2
84
- prpu[1] + "0"*(2-prpu.last.size)
85
- else
86
- prpu[1][0,2]
87
- end
88
- else
89
- '00'
90
- end
91
- prpu = pre.to_s + las.to_s
92
- row << "%#{LEN[:PRPU]}s" % prpu[0,LEN[:PRPU]]
110
+ row << "%#{LEN[:PRMO]}s" % format_price(cols[COL[:PRMO]])
111
+ row << "%#{LEN[:PRPU]}s" % format_price(cols[COL[:PRPU]])
93
112
  row << "%#{LEN[:CKZL]}s" % if cols[COL[:CKZL1]] =~ /Ja/
94
113
  1
95
114
  elsif cols[COL[:CKZL2]] =~ /Ja/
@@ -104,7 +123,7 @@ class Oddb2tdat
104
123
  else
105
124
  0
106
125
  end
107
- row << "%0#{LEN[:ITHE]}d" % cols[COL[:ITHE]].gsub('.','').to_i
126
+ row << "%#{LEN[:ITHE]}s" % format_date(cols[COL[:ITHE]])
108
127
  row << "%#{LEN[:CEAN]}s" % cols[COL[:CEAN]]
109
128
  @rows << row
110
129
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oddb2tdat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Masaomi Hatakeyama, Zeno R.R. Davatz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-12 00:00:00 +01:00
18
+ date: 2012-01-13 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency