openils-mapper 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/edi/edi2json.rb +16 -6
- data/lib/openils/mapper.rb +13 -8
- data/test/map_spec.rb +1 -1
- data/test/openils_map_spec.rb +1 -1
- metadata +77 -29
data/lib/edi/edi2json.rb
CHANGED
@@ -4,6 +4,16 @@ module EDI
|
|
4
4
|
|
5
5
|
class Collection
|
6
6
|
include Enumerable
|
7
|
+
|
8
|
+
def hash_name
|
9
|
+
# If this is the trigger node for a segment group, use the
|
10
|
+
# group name. Otherwise, use the segment name.
|
11
|
+
if self.respond_to?(:is_tnode?) and self.is_tnode?
|
12
|
+
self.sg_name
|
13
|
+
else
|
14
|
+
self.name
|
15
|
+
end
|
16
|
+
end
|
7
17
|
|
8
18
|
def to_hash
|
9
19
|
result = {}
|
@@ -36,13 +46,13 @@ class Collection
|
|
36
46
|
end
|
37
47
|
}
|
38
48
|
|
39
|
-
#
|
40
|
-
|
41
|
-
|
49
|
+
# If this is the trigger node for a segment group,
|
50
|
+
# make this the first segment in the group.
|
51
|
+
if self.respond_to?(:is_tnode?) and self.is_tnode?
|
52
|
+
result = [[self.name, result]]
|
42
53
|
self.children.each { |segment|
|
43
|
-
|
54
|
+
result << [segment.hash_name, segment.to_hash]
|
44
55
|
}
|
45
|
-
result[self.sg_name] = segments
|
46
56
|
end
|
47
57
|
|
48
58
|
result
|
@@ -89,7 +99,7 @@ class Message
|
|
89
99
|
self.find_all { |segment|
|
90
100
|
segment.level < 2
|
91
101
|
}.each { |segment|
|
92
|
-
segments << [segment.
|
102
|
+
segments << [segment.hash_name, segment.to_hash]
|
93
103
|
}
|
94
104
|
segments << [self.trailer.name, self.trailer.to_hash]
|
95
105
|
segments
|
data/lib/openils/mapper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'edi/mapper'
|
|
3
3
|
module OpenILS
|
4
4
|
|
5
5
|
class Mapper < EDI::E::Mapper
|
6
|
-
VERSION = '0.9.
|
6
|
+
VERSION = '0.9.2'
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
@@ -38,8 +38,17 @@ OpenILS::Mapper.map 'order' do |mapper,key,value|
|
|
38
38
|
mapper.add("CNT", { 'C270' => { '6066' => value['line_items'] } })
|
39
39
|
end
|
40
40
|
|
41
|
+
def map_identifier(data)
|
42
|
+
id = { '7140' => data['id'] }
|
43
|
+
if data['id-qualifier']
|
44
|
+
id['7143'] = data['id-qualifier']
|
45
|
+
end
|
46
|
+
id
|
47
|
+
end
|
48
|
+
|
41
49
|
OpenILS::Mapper.map 'item' do |mapper,key,value|
|
42
|
-
|
50
|
+
primary_id = map_identifier(value['identifiers'].first)
|
51
|
+
mapper.add('LIN', { 'C212' => primary_id, '1082' => value['line_index'] })
|
43
52
|
|
44
53
|
# use Array#inject() to group the identifiers in groups of 5.
|
45
54
|
# Same as Array#in_groups_of() without the active_support dependency.
|
@@ -49,15 +58,11 @@ OpenILS::Mapper.map 'item' do |mapper,key,value|
|
|
49
58
|
result << []
|
50
59
|
end
|
51
60
|
result
|
52
|
-
}
|
61
|
+
}.reject { |group| group.empty? }
|
53
62
|
|
54
63
|
id_groups.each { |group|
|
55
64
|
ids = group.compact.collect { |data|
|
56
|
-
|
57
|
-
if data['id-qualifier']
|
58
|
-
id['7143'] = data['id-qualifier']
|
59
|
-
end
|
60
|
-
id
|
65
|
+
map_identifier(data)
|
61
66
|
}
|
62
67
|
mapper.add('PIA',{ 'C212' => ids })
|
63
68
|
}
|
data/test/map_spec.rb
CHANGED
@@ -114,7 +114,7 @@ describe EDI::E::Mapper do
|
|
114
114
|
}
|
115
115
|
# Can't compare everything because of timestamping, so we'll just compare
|
116
116
|
# the bodies for a high degree of confidence
|
117
|
-
interchange.to_hash['body'].should == [{"ORDERS"=>[["UNH", {"S009"=>{"0052"=>"D", "0054"=>"96A", "0065"=>"ORDERS", "0051"=>"UN"}, "0062"=>"1"}], ["BGM", {"1225"=>"9", "C002"=>{"1001"=>"220"}, "1004"=>"2"}], ["DTM", {"C507"=>{"2379"=>"102", "2380"=>"20090331", "2005"=>"137"}}], ["NAD", {"
|
117
|
+
interchange.to_hash['body'].should == [{"ORDERS"=>[["UNH", {"S009"=>{"0052"=>"D", "0054"=>"96A", "0065"=>"ORDERS", "0051"=>"UN"}, "0062"=>"1"}], ["BGM", {"1225"=>"9", "C002"=>{"1001"=>"220"}, "1004"=>"2"}], ["DTM", {"C507"=>{"2379"=>"102", "2380"=>"20090331", "2005"=>"137"}}], ["NAD", {"3035"=>"BY", "SG2"=>[["RFF", {"C506"=>{"1153"=>"API", "1154"=>"3472205 0001"}}]], "C082"=>{"3039"=>"3472205", "3055"=>"91"}}], ["NAD", {"3035"=>"BY", "SG2"=>[["RFF", {"C506"=>{"1153"=>"API", "1154"=>"3472205 0001"}}]], "C082"=>{"3039"=>"3472205", "3055"=>"31B"}}], ["NAD", {"3035"=>"SU", "C082"=>{"3039"=>"1556150", "3055"=>"31B"}}], ["NAD", {"3035"=>"SU", "SG2"=>[["RFF", {"C506"=>{"1153"=>"IA", "1154"=>"1865"}}]], "C082"=>{"3039"=>"1556150", "3055"=>"91"}}], ["CUX", {"C504"=>[{"6345"=>"USD", "6347"=>"2", "6343"=>"9"}]}], ["LIN", {"SG25"=>[["PIA", {"4347"=>"5", "C212"=>[{"7140"=>"03-0010837", "7143"=>"SA"}]}], ["IMD", {"C273"=>{"7008"=>["Discernment"]}, "7077"=>"F", "7081"=>"BTI"}], ["IMD", {"C273"=>{"7008"=>["Concord Records,"]}, "7077"=>"F", "7081"=>"BPU"}], ["IMD", {"C273"=>{"7008"=>["1986."]}, "7077"=>"F", "7081"=>"BPD"}], ["IMD", {"C273"=>{"7008"=>["1 sound disc :"]}, "7077"=>"F", "7081"=>"BPH"}], ["QTY", {"C186"=>{"6060"=>2, "6063"=>"21"}}], ["PRI", {"C509"=>{"5125"=>"AAB", "5118"=>35.95}}], ["RFF", {"C506"=>{"1153"=>"LI", "1154"=>"2/1"}}]], "1082"=>1}], ["LIN", {"SG25"=>[["PIA", {"4347"=>"5", "C212"=>[{"7140"=>"03-0010840", "7143"=>"SA"}]}], ["IMD", {"C273"=>{"7008"=>["The inner source"]}, "7077"=>"F", "7081"=>"BTI"}], ["IMD", {"C273"=>{"7008"=>["Duke, George, 1946-"]}, "7077"=>"F", "7081"=>"BAU"}], ["IMD", {"C273"=>{"7008"=>["MPS Records,"]}, "7077"=>"F", "7081"=>"BPU"}], ["IMD", {"C273"=>{"7008"=>["1973."]}, "7077"=>"F", "7081"=>"BPD"}], ["IMD", {"C273"=>{"7008"=>["2 sound discs :"]}, "7077"=>"F", "7081"=>"BPH"}], ["QTY", {"C186"=>{"6060"=>1, "6063"=>"21"}}], ["PRI", {"C509"=>{"5125"=>"AAB", "5118"=>28.95}}], ["RFF", {"C506"=>{"1153"=>"LI", "1154"=>"2/2"}}]], "1082"=>2}], ["UNS", {"0081"=>"S"}], ["CNT", {"C270"=>{"6069"=>"2", "6066"=>2}}], ["UNT", {"0074"=>33, "0062"=>"1"}]]}]
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|
data/test/openils_map_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe OpenILS::Mapper do
|
|
34
34
|
it "should create a message from high-level JEDI input" do
|
35
35
|
json = File.read(File.join(File.dirname(__FILE__), 'test_po.json'))
|
36
36
|
@map = OpenILS::Mapper.from_json(%{{ "body": [{ "ORDERS": #{json}}], "sender": "123456", "recipient": {"id": "999999999", "id-qualifier": "1"}}})
|
37
|
-
@map.message.to_s.should == "UNH+1+ORDERS:D:96A:UN'BGM+220+2+9'DTM+137:20090331:102'NAD+BY+3472205::91'RFF+API:3472205 0001'NAD+BY+3472205::31B'RFF+API:3472205 0001'NAD+SU+1556150::31B'NAD+SU+1556150::91'RFF+IA:1865'CUX+2:USD:9'LIN+1'PIA+5+03-0010837:SA'IMD+F+BTI+:::Discernment'IMD+F+BPU+:::Concord Records,'IMD+F+BPD+:::1986.'IMD+F+BPH+:::1 sound disc ?:'QTY+21:2'PRI+AAB:35.95'RFF+LI:2/1'LIN+2'PIA+5+03-0010840:SA'IMD+F+BTI+:::The inner source'IMD+F+BAU+:::Duke, George, 1946-'IMD+F+BPU+:::MPS Records,'IMD+F+BPD+:::1973.'IMD+F+BPH+:::2 sound discs ?:'QTY+21:1'PRI+AAB:28.95'RFF+LI:2/2'UNS+S'CNT+2:2'UNT+33+1'"
|
37
|
+
@map.message.to_s.should == "UNH+1+ORDERS:D:96A:UN'BGM+220+2+9'DTM+137:20090331:102'NAD+BY+3472205::91'RFF+API:3472205 0001'NAD+BY+3472205::31B'RFF+API:3472205 0001'NAD+SU+1556150::31B'NAD+SU+1556150::91'RFF+IA:1865'CUX+2:USD:9'LIN+1++03-0010837:SA'PIA+5+03-0010837:SA'IMD+F+BTI+:::Discernment'IMD+F+BPU+:::Concord Records,'IMD+F+BPD+:::1986.'IMD+F+BPH+:::1 sound disc ?:'QTY+21:2'PRI+AAB:35.95'RFF+LI:2/1'LIN+2++03-0010840:SA'PIA+5+03-0010840:SA'IMD+F+BTI+:::The inner source'IMD+F+BAU+:::Duke, George, 1946-'IMD+F+BPU+:::MPS Records,'IMD+F+BPD+:::1973.'IMD+F+BPH+:::2 sound discs ?:'QTY+21:1'PRI+AAB:28.95'RFF+LI:2/2'UNS+S'CNT+2:2'UNT+33+1'"
|
38
38
|
@map.header.cS002.to_s.should == "123456:31B"
|
39
39
|
@map.header.cS003.to_s.should == "999999999:1"
|
40
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openils-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 63
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 2
|
10
|
+
version: 0.9.2
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Michael B. Klein
|
@@ -9,69 +15,105 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-07-06 00:00:00 -07:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: edi4r
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 51
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 4
|
23
34
|
version: 0.9.4
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: edi4r-tdid
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 6
|
49
|
+
- 5
|
33
50
|
version: 0.6.5
|
34
|
-
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
35
53
|
- !ruby/object:Gem::Dependency
|
36
54
|
name: json
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
40
58
|
requirements:
|
41
59
|
- - ">="
|
42
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 21
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 1
|
65
|
+
- 3
|
43
66
|
version: 1.1.3
|
44
|
-
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
45
69
|
- !ruby/object:Gem::Dependency
|
46
70
|
name: rcov
|
47
|
-
|
48
|
-
|
49
|
-
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
50
74
|
requirements:
|
51
75
|
- - ">="
|
52
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 61
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 8
|
81
|
+
- 1
|
53
82
|
version: 0.8.1
|
54
|
-
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
55
85
|
- !ruby/object:Gem::Dependency
|
56
86
|
name: rspec
|
57
|
-
|
58
|
-
|
59
|
-
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
60
90
|
requirements:
|
61
91
|
- - ">="
|
62
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 27
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 2
|
97
|
+
- 2
|
63
98
|
version: 1.2.2
|
64
|
-
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id005
|
65
101
|
- !ruby/object:Gem::Dependency
|
66
102
|
name: rake
|
67
|
-
|
68
|
-
|
69
|
-
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
70
106
|
requirements:
|
71
107
|
- - ">="
|
72
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 63
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 8
|
113
|
+
- 0
|
73
114
|
version: 0.8.0
|
74
|
-
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
75
117
|
description: Middleware layer to provide translation between high-level JSON and raw EDIFACT messages
|
76
118
|
email: mbklein@gmail.com
|
77
119
|
executables: []
|
@@ -101,21 +143,27 @@ rdoc_options:
|
|
101
143
|
require_paths:
|
102
144
|
- lib
|
103
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
104
147
|
requirements:
|
105
148
|
- - ">="
|
106
149
|
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
107
153
|
version: "0"
|
108
|
-
version:
|
109
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
110
156
|
requirements:
|
111
157
|
- - ">="
|
112
158
|
- !ruby/object:Gem::Version
|
159
|
+
hash: 3
|
160
|
+
segments:
|
161
|
+
- 0
|
113
162
|
version: "0"
|
114
|
-
version:
|
115
163
|
requirements: []
|
116
164
|
|
117
165
|
rubyforge_project:
|
118
|
-
rubygems_version: 1.3.
|
166
|
+
rubygems_version: 1.3.7
|
119
167
|
signing_key:
|
120
168
|
specification_version: 3
|
121
169
|
summary: EDIFACT<->JSON middleware for the Evergreen Open Source ILS
|