openils-mapper 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/edi/mapper.rb +12 -0
  2. data/lib/openils/mapper.rb +10 -5
  3. metadata +4 -4
data/lib/edi/mapper.rb CHANGED
@@ -15,6 +15,18 @@ class String
15
15
  self.scan(re).flatten.reject { |chunk| chunk.nil? or chunk.empty? }
16
16
  end
17
17
 
18
+ def chunk_and_group(chunk_len, group_len)
19
+ chunks = self.chunk(chunk_len)
20
+ groups = [[]]
21
+ chunks.each { |chunk|
22
+ if groups.last.length == group_len
23
+ groups << []
24
+ end
25
+ groups.last << chunk
26
+ }
27
+ groups
28
+ end
29
+
18
30
  end
19
31
 
20
32
  module EDI::E
@@ -3,7 +3,7 @@ require 'edi/mapper'
3
3
  module OpenILS
4
4
 
5
5
  class Mapper < EDI::E::Mapper
6
- VERSION = '0.9.4'
6
+ VERSION = '0.9.5'
7
7
  end
8
8
 
9
9
  end
@@ -68,6 +68,12 @@ OpenILS::Mapper.map 'item' do |mapper,key,value|
68
68
  }
69
69
  value['desc'].each { |desc| mapper.add('desc',desc) }
70
70
  mapper.add('QTY', { 'C186' => { '6060' => value['quantity'] } })
71
+ if value.has_key?('free-text')
72
+ chunked_text = value['free-text'].chunk_and_group(512,5)
73
+ chunked_text.each { |data|
74
+ mapper.add('FTX', { '4451' => 'LIN', 'C108' => { '4440' => data } })
75
+ }
76
+ end
71
77
  mapper.add('PRI', { 'C509' => { '5118' => value['price'] } })
72
78
  mapper.add('RFF', { 'C506' => { '1153' => 'LI', '1154' => value['line_number'] } })
73
79
  end
@@ -106,10 +112,9 @@ OpenILS::Mapper.map 'desc' do |mapper,key,value|
106
112
  code = values.shift
107
113
  text = values.shift.to_s
108
114
  code_qual = code =~ /^[0-9]+$/ ? 'L' : 'F'
109
- chunked_text = text.chunk(35)
110
- while chunked_text.length > 0
111
- data = [chunked_text.shift,chunked_text.shift].compact
115
+ chunked_text = text.chunk_and_group(35,2)
116
+ chunked_text.each { |data|
112
117
  mapper.add('IMD', { '7077' => code_qual, '7081' => code, 'C273' => { '7008' => data } })
113
- end
118
+ }
114
119
  end
115
120
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openils-mapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 4
10
- version: 0.9.4
9
+ - 5
10
+ version: 0.9.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael B. Klein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-27 00:00:00 -07:00
18
+ date: 2010-08-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency