libis-tools 0.9.9 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -2
  3. data/README.md +19 -0
  4. data/lib/libis/tools.rb +1 -0
  5. data/lib/libis/tools/config_file.rb +1 -1
  6. data/lib/libis/tools/extend/kernel.rb +16 -0
  7. data/lib/libis/tools/metadata.rb +20 -0
  8. data/lib/libis/tools/metadata/dublin_core_record.rb +1 -1
  9. data/lib/libis/tools/metadata/{field_spec.rb → field_format.rb} +7 -7
  10. data/lib/libis/tools/metadata/fix_field.rb +6 -1
  11. data/lib/libis/tools/metadata/mapper.rb +80 -0
  12. data/lib/libis/tools/metadata/mappers/flandrica.rb +69 -0
  13. data/lib/libis/tools/metadata/mappers/kuleuven.rb +1702 -0
  14. data/lib/libis/tools/metadata/marc21_record.rb +5 -4
  15. data/lib/libis/tools/metadata/marc_record.rb +96 -37
  16. data/lib/libis/tools/metadata/parser/basic_parser.rb +118 -0
  17. data/lib/libis/tools/metadata/parser/dublin_core_parser.rb +36 -0
  18. data/lib/libis/tools/metadata/parser/marc21_parser.rb +206 -0
  19. data/lib/libis/tools/metadata/parser/marc_format_parser.rb +52 -0
  20. data/lib/libis/tools/metadata/parser/marc_rules.rb +35 -0
  21. data/lib/libis/tools/metadata/parser/marc_select_parser.rb +25 -0
  22. data/lib/libis/tools/metadata/parser/patch.rb +21 -0
  23. data/lib/libis/tools/metadata/parser/subfield_criteria_parser.rb +71 -0
  24. data/lib/libis/tools/metadata/parsers.rb +12 -0
  25. data/lib/libis/tools/metadata/var_field.rb +57 -47
  26. data/lib/libis/tools/parameter.rb +12 -2
  27. data/lib/libis/tools/version.rb +1 -1
  28. data/libis-tools.gemspec +4 -3
  29. data/spec/config_spec.rb +3 -1
  30. data/spec/data/MetadataMapping.xlsx +0 -0
  31. data/spec/metadata/8389207.marc +96 -0
  32. data/spec/metadata/dublin_core_parser_spec.rb +48 -0
  33. data/spec/metadata/marc21_parser_data.rb +382 -0
  34. data/spec/metadata/marc21_parser_spec.rb +67 -0
  35. data/spec/metadata/marc21_spec.rb +116 -0
  36. data/spec/metadata/metadata_mapper_spec.rb +23 -0
  37. data/spec/spec_helper.rb +13 -0
  38. data/test.rb +61 -0
  39. metadata +77 -7
  40. data/lib/libis/tools/dc_record.rb +0 -47
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Tools
3
- VERSION = '0.9.9'
3
+ VERSION = '0.9.10'
4
4
  end
5
5
  end
data/libis-tools.gemspec CHANGED
@@ -29,13 +29,14 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rspec', '~> 3.1'
30
30
  spec.add_development_dependency 'simplecov', '~> 0.9'
31
31
  spec.add_development_dependency 'equivalent-xml', '~> 0.5'
32
-
32
+ spec.add_development_dependency 'awesome_print'
33
33
 
34
34
  spec.add_runtime_dependency 'backports', '~> 3.6'
35
35
  spec.add_runtime_dependency 'savon', '~> 2.0'
36
36
  spec.add_runtime_dependency 'nokogiri', '~> 1.6'
37
37
  spec.add_runtime_dependency 'gyoku', '~> 1.2'
38
38
  spec.add_runtime_dependency 'nori', '~> 2.4'
39
- spec.add_runtime_dependency 'recursive-open-struct', '~>0.6.4'
40
-
39
+ spec.add_runtime_dependency 'recursive-open-struct', '~> 0.6'
40
+ spec.add_runtime_dependency 'parslet', '~> 1.7'
41
+ spec.add_runtime_dependency 'simple_xlsx_reader', '~> 1.0'
41
42
  end
data/spec/config_spec.rb CHANGED
@@ -64,7 +64,9 @@ describe 'Config' do
64
64
  context 'loading from file' do
65
65
 
66
66
  let(:test_file) { File.join(File.dirname(__FILE__), 'data', 'test.yml') }
67
- subject(:config) { Libis::Tools::Config.clear! << test_file }
67
+ subject(:config) {
68
+ Libis::Tools::Config.clear! << test_file
69
+ }
68
70
 
69
71
  it 'has configuration parameters set' do
70
72
  expect(config.process).to eq 'Test Configuration'
Binary file
@@ -0,0 +1,96 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <record xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
3
+ xmlns="http://www.loc.gov/MARC21/slim" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4
+ <leader>01068nam 2200241u 4500</leader>
5
+ <controlfield tag="005">20150701153710.0</controlfield>
6
+ <controlfield tag="008">000608m17221724xx |||| | 000|0 lat c</controlfield>
7
+ <controlfield tag="001">9921543960101471</controlfield>
8
+ <datafield tag="035" ind1=" " ind2=" ">
9
+ <subfield code="a">(BeLVLBS)002154396LBS01-Aleph</subfield>
10
+ </datafield>
11
+ <datafield tag="035" ind1=" " ind2=" ">
12
+ <subfield code="a">8389207</subfield>
13
+ </datafield>
14
+ <datafield tag="245" ind1="0" ind2="0">
15
+ <subfield code="a">Anecdota Graeca, sacra et profana /</subfield>
16
+ <subfield code="c">ex codicibus manu exaratis nunc primum in lucem edita, versione Latina donata, et notis
17
+ illustrata a Io. Christophoro Wolfio ... Tom. I [-IIII]
18
+ </subfield>
19
+ </datafield>
20
+ <datafield tag="264" ind1=" " ind2="1">
21
+ <subfield code="a">Hamburgi</subfield>
22
+ <subfield code="b">apud Theodorum Christophorum Felginer,</subfield>
23
+ <subfield code="c">1722-1724</subfield>
24
+ </datafield>
25
+ <datafield tag="300" ind1=" " ind2=" ">
26
+ <subfield code="a">8o: 4 v.; [22], 298, [8]; [16], 354, [1]; [16], 299, [7]; [16], 271, [5] p.</subfield>
27
+ </datafield>
28
+ <datafield tag="336" ind1=" " ind2=" ">
29
+ <subfield code="a">text</subfield>
30
+ <subfield code="2">rdacontent</subfield>
31
+ </datafield>
32
+ <datafield tag="337" ind1=" " ind2=" ">
33
+ <subfield code="a">unmediated</subfield>
34
+ <subfield code="2">rdamedia</subfield>
35
+ </datafield>
36
+ <datafield tag="338" ind1=" " ind2=" ">
37
+ <subfield code="a">volume</subfield>
38
+ <subfield code="2">rdacarrier</subfield>
39
+ </datafield>
40
+ <datafield tag="500" ind1=" " ind2=" ">
41
+ <subfield code="a">Ded. Petrus Theodorus Seelmann; Erdmannus Neumeister; Thomas Claussen; Joannes Grammius
42
+ </subfield>
43
+ </datafield>
44
+ <datafield tag="500" ind1=" " ind2=" ">
45
+ <subfield code="a">Elk deel heeft eigen titelp. in roodzwartdruk, met drukkersmerk</subfield>
46
+ </datafield>
47
+ <datafield tag="650" ind1=" " ind2="7">
48
+ <subfield code="2">UDC</subfield>
49
+ <subfield code="a">276 =75</subfield>
50
+ <subfield code="x">Griekse patrologie</subfield>
51
+ </datafield>
52
+ <datafield tag="653" ind1=" " ind2="6">
53
+ <subfield code="a">Books before 1840</subfield>
54
+ </datafield>
55
+ <datafield tag="700" ind1="1" ind2=" ">
56
+ <subfield code="a">Wolf, Johann Christoph</subfield>
57
+ <subfield code="d">1683-1739</subfield>
58
+ <subfield code="4">aut</subfield>
59
+ </datafield>
60
+ <datafield tag="953" ind1=" " ind2=" ">
61
+ <subfield code="a">1701-1750</subfield>
62
+ </datafield>
63
+ <datafield tag="998" ind1=" " ind2=" ">
64
+ <subfield code="a">LBS01</subfield>
65
+ <subfield code="b">bib_200501.mrc.2.av</subfield>
66
+ </datafield>
67
+ <datafield tag="INST" ind1=" " ind2=" ">
68
+ <subfield code="a">32KUL_LIBIS_NETWORK</subfield>
69
+ <subfield code="b">P</subfield>
70
+ <subfield code="c">71134440820001471</subfield>
71
+ </datafield>
72
+ <datafield tag="INST" ind1=" " ind2=" ">
73
+ <subfield code="a">32KUL_KUL</subfield>
74
+ <subfield code="b">P</subfield>
75
+ <subfield code="c">21304345390001488</subfield>
76
+ </datafield>
77
+ <datafield tag="AVA" ind1=" " ind2=" ">
78
+ <subfield code="a">32KUL_KUL</subfield>
79
+ <subfield code="b">GBIB</subfield>
80
+ <subfield code="c">GBIB: Godgeleerdheid</subfield>
81
+ <subfield code="d">276.030.4 WOLF Anec</subfield>
82
+ <subfield code="e">available</subfield>
83
+ <subfield code="f">1</subfield>
84
+ <subfield code="g">0</subfield>
85
+ <subfield code="j">GBIB</subfield>
86
+ <subfield code="p">1</subfield>
87
+ </datafield>
88
+ <datafield tag="MMS" ind1=" " ind2=" ">
89
+ <subfield code="b">9921543960101471</subfield>
90
+ <subfield code="a">32KUL_LIBIS_NETWORK</subfield>
91
+ </datafield>
92
+ <datafield tag="MMS" ind1=" " ind2=" ">
93
+ <subfield code="b">9921543960101488</subfield>
94
+ <subfield code="a">32KUL_KUL</subfield>
95
+ </datafield>
96
+ </record>
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require 'libis/tools/metadata/parsers'
4
+ require 'parslet'
5
+ require 'parslet/convenience'
6
+ require 'pp'
7
+
8
+ $DEBUG = false
9
+
10
+ describe 'DublinCore Parser' do
11
+
12
+ subject(:parser) { Libis::Tools::Metadata::DublinCoreParser.new }
13
+
14
+ it 'parses simple DC' do
15
+ expect {
16
+ tree = parser.parse_with_debug('dc:title')
17
+ # pp tree
18
+ expect(tree).to be_a Hash
19
+ expect(tree[:namespace]).to eq 'dc'
20
+ expect(tree[:element]).to eq 'title'
21
+ # noinspection RubyResolve
22
+ expect(tree).not_to have_key :attributes
23
+ }.not_to raise_error
24
+ end
25
+
26
+ it 'must see namespace' do
27
+ expect {
28
+ parser.parse('title')
29
+ }.to raise_error(Parslet::ParseFailed)
30
+ end
31
+
32
+ it 'parses DC with attributes' do
33
+ expect {
34
+ tree = parser.parse_with_debug('dcterms:date xsi:type="http://example.com" foo:bar="baz"')
35
+ # pp tree
36
+ expect(tree).to be_a Hash
37
+ expect(tree[:namespace]).to eq 'dcterms'
38
+ expect(tree[:element]).to eq 'date'
39
+ # noinspection RubyResolve
40
+ expect(tree[:attributes].size).to be 2
41
+ expect(tree[:attributes]).to eq [
42
+ {namespace: 'xsi', name: 'type', value: 'http://example.com'},
43
+ {namespace: 'foo', name: 'bar', value: 'baz'},
44
+ ]
45
+ }.not_to raise_error
46
+ end
47
+
48
+ end
@@ -0,0 +1,382 @@
1
+ def marc21_parser_testdata
2
+ [
3
+ {
4
+ title: 'select statement with numeric tag',
5
+ input: 'MARC 123',
6
+ tree: {tag: '123', ind1: nil, ind2: nil, subfield: nil, condition: nil},
7
+ transform: "record.select_fields('123##')"
8
+ }, {
9
+ title: 'select statement with LRK tag',
10
+ input: 'MARC LKR',
11
+ tree: {tag: 'LKR', ind1: nil, ind2: nil, subfield: nil, condition: nil},
12
+ transform: "record.select_fields('LKR##')"
13
+ }, {
14
+ title: 'select statement with FMT tag',
15
+ input: 'MARC FMT',
16
+ tree: {tag: 'FMT', ind1: nil, ind2: nil, subfield: nil, condition: nil},
17
+ transform: "record.select_fields('FMT##')"
18
+ }, {
19
+ title: 'select statement with bad magic text',
20
+ input: 'foo',
21
+ tree: :failure
22
+ }, {
23
+ title: 'select statement with bad tag',
24
+ input: 'MARC 1',
25
+ tree: :failure
26
+ }, {
27
+ title: 'select statement with bad indicator',
28
+ input: 'MARC 123 *',
29
+ tree: :failure
30
+ }, {
31
+ title: 'select statement with bad subfield',
32
+ input: 'MARC 123 $_',
33
+ tree: :failure
34
+ }, {
35
+ title: 'select statement with tag and one indicator',
36
+ input: 'MARC 123 #',
37
+ tree: {tag: '123', ind1: '#', ind2: nil, subfield: nil, condition: nil},
38
+ transform: "record.select_fields('123##')"
39
+ }, {
40
+ title: 'select statement with tag and indicators',
41
+ input: 'MARC 123 #_',
42
+ tree: {tag: '123', ind1: '#', ind2: '_', subfield: nil, condition: nil},
43
+ transform: "record.select_fields('123#_')"
44
+ }, {
45
+ title: 'select statement with tag and subfield',
46
+ input: 'MARC 123 $a',
47
+ tree: {tag: '123', ind1: nil, ind2: nil, subfield: {name: 'a'}, condition: nil},
48
+ transform: "record.select_fields('123##a')"
49
+ }, {
50
+ title: 'select statement with tag, indicators and subfield',
51
+ input: 'MARC 123 45 $6',
52
+ tree: {tag: '123', ind1: '4', ind2: '5', subfield: {name: '6'}, condition: nil},
53
+ transform: "record.select_fields('123456')"
54
+ }, {
55
+ title: 'select statement with subfield condition',
56
+ input: 'MARC 123 [f.match(\'a\')]',
57
+ tree: {
58
+ tag: '123', ind1: nil, ind2: nil, subfield: nil,
59
+ condition: {
60
+ cond_format: {
61
+ entry: [
62
+ {cond_group: {
63
+ prefix: 'f.match',
64
+ lparen: '(',
65
+ entry: [
66
+ {cond_group: {
67
+ prefix: nil,
68
+ lparen: "'",
69
+ entry: nil,
70
+ postfix: 'a',
71
+ rparen: "'"
72
+ }}
73
+ ],
74
+ postfix: nil,
75
+ rparen: ')'
76
+ }}
77
+ ],
78
+ postfix: nil
79
+ }
80
+ }
81
+ },
82
+ transform: "record.select_fields('123##', Proc.new { |f| f.match('a') })"
83
+ }, {
84
+ title: 'select statement with regex condition',
85
+ input: 'MARC 123 [$0 =~ /^.+"ABC"/]',
86
+ tree: {
87
+ tag: '123', ind1: nil, ind2: nil, subfield: nil,
88
+ condition: {
89
+ cond_format: {
90
+ entry: [
91
+ {subfield: {:prefix => nil, :repeat => nil, :name => '0'}},
92
+ {cond_group: {
93
+ prefix: ' =~ /^.+',
94
+ lparen: "\"",
95
+ entry: nil,
96
+ postfix: 'ABC',
97
+ rparen: "\""
98
+ }}
99
+ ],
100
+ postfix: '/'
101
+ }
102
+ }
103
+ },
104
+ transform: "record.select_fields('123##', Proc.new { |f| f.subfield('0') =~ /^.+\"ABC\"/ })"
105
+ }, {
106
+ title: 'select statement with complex regex condition',
107
+ input: 'MARC 690 02 {$0 =~ /^\(ODIS-(PS|ORG)\) (\d)+$$/}',
108
+ tree: {
109
+ tag: '690', ind1: '0', ind2: '2', subfield: nil,
110
+ condition: {
111
+ cond_format: {
112
+ entry: [
113
+ {subfield: {prefix: nil, repeat: nil, name: '0'}},
114
+ {cond_group: {prefix: " =~ /^\\",
115
+ lparen: '(',
116
+ entry: [
117
+ {cond_group: {
118
+ prefix: 'ODIS-',
119
+ lparen: '(',
120
+ entry: nil,
121
+ postfix: 'PS|ORG',
122
+ rparen: ')'}}
123
+ ],
124
+ postfix: "\\",
125
+ rparen: ')'}},
126
+ {cond_group: {
127
+ prefix: ' ',
128
+ lparen: '(',
129
+ entry: nil,
130
+ postfix: "\\d",
131
+ rparen: ')'}}
132
+ ],
133
+ postfix: '+$$/'}}
134
+ },
135
+ transform: "record.select_fields('69002', Proc.new { |f| f.subfield('0') =~ /^\\(ODIS-(PS|ORG)\\) (\\d)+$$/ })"
136
+ }, {
137
+ }, {
138
+ title: 'format statement with simple subfield reference',
139
+ input: '$a',
140
+ tree: {entry: [{subfield: {prefix: nil, repeat: nil, name: 'a'}}], postfix: nil},
141
+ transform: "f.subfield('a')"
142
+ }, {
143
+ title: 'format statement with subfield reference with repeat indicator',
144
+ input: '$*a',
145
+ tree: {entry: [{subfield: {prefix: nil, repeat: '*', name: 'a'}}], postfix: nil},
146
+ transform: "field_format(f.subfield_array('a'), join: ';').to_s"
147
+ }, {
148
+ title: 'format statement with subfield reference with repeat + separator indicator',
149
+ input: '$*"; "a',
150
+ tree: {entry: [{subfield: {prefix: nil, repeat: {separator: '; '}, name: 'a'}}], postfix: nil},
151
+ transform: "field_format(f.subfield_array('a'), join: '; ').to_s"
152
+ }, {
153
+ title: 'format statement with position reference',
154
+ input: '$[13]',
155
+ tree: {entry: [{fixfield: {prefix: nil, position: '13'}}], postfix: nil},
156
+ transform: 'f[13]'
157
+ }, {
158
+ title: 'format statement with range reference',
159
+ input: 'abc: $[5-8]',
160
+ tree: {entry: [{fixfield: {prefix: 'abc: ', first: '5', last: '8'}}], postfix: nil},
161
+ transform: "field_format(f[5,8], prefix: 'abc: ').to_s"
162
+ }, {
163
+ title: 'format statement with all range reference',
164
+ input: 'abc: $[*].',
165
+ tree: {entry: [{fixfield: {prefix: 'abc: ', all: '*'}}], postfix: '.'},
166
+ transform: "field_format(field_format(f[], prefix: 'abc: ').to_s, postfix: '.').to_s"
167
+ }, {
168
+ title: 'format statement with multiple subfields with prefixes',
169
+ input: '$a, $b - $c',
170
+ tree: {
171
+ entry: [
172
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
173
+ {subfield: {prefix: ', ', repeat: nil, name: 'b'}},
174
+ {subfield: {prefix: ' - ', repeat: nil, name: 'c'}},
175
+ ],
176
+ postfix: nil},
177
+ transform: "field_format(f.subfield('a'),field_format(f.subfield('b'), prefix: ', ').to_s,field_format(f.subfield('c'), prefix: ' - ').to_s).to_s"
178
+ }, {
179
+ title: 'format statement with multiple subfields with prefixes and postfix',
180
+ input: '$a, $b - $c.',
181
+ tree: {
182
+ entry: [
183
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
184
+ {subfield: {prefix: ', ', repeat: nil, name: 'b'}},
185
+ {subfield: {prefix: ' - ', repeat: nil, name: 'c'}},
186
+ ],
187
+ postfix: '.'},
188
+ transform: "field_format(f.subfield('a'),field_format(f.subfield('b'), prefix: ', ').to_s,field_format(f.subfield('c'), prefix: ' - ').to_s, postfix: '.').to_s"
189
+ }, {
190
+ title: 'format statement with multiple subfields with prefixes and group',
191
+ input: '$a, $b - ($c)',
192
+ tree: {
193
+ entry: [
194
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
195
+ {subfield: {prefix: ', ', repeat: nil, name: 'b'}},
196
+ {group: {
197
+ prefix: ' - ', postfix: nil,
198
+ lparen: '(', rparen: ')',
199
+ entry: [{subfield: {prefix: nil, repeat: nil, name: 'c'}}]
200
+ }},
201
+ ],
202
+ postfix: nil},
203
+ transform: "field_format(f.subfield('a'),field_format(f.subfield('b'), prefix: ', ').to_s,field_format(f.subfield('c'), prefix: ' - (', postfix: ')').to_s).to_s"
204
+ }, {
205
+ title: 'format statement with multiple subfields with prefixes and group with multiple entries',
206
+ input: '$a, $b - ($c, $d, ...)',
207
+ tree: {
208
+ entry: [
209
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
210
+ {subfield: {prefix: ', ', repeat: nil, name: 'b'}},
211
+ {group: {
212
+ prefix: ' - ', postfix: ', ...',
213
+ lparen: '(', rparen: ')',
214
+ entry: [
215
+ {subfield: {prefix: nil, repeat: nil, name: 'c'}},
216
+ {subfield: {prefix: ', ', repeat: nil, name: 'd'}},
217
+ ],
218
+ }},
219
+ ],
220
+ postfix: nil},
221
+ transform: "field_format(f.subfield('a'),field_format(f.subfield('b'), prefix: ', ').to_s,field_format(f.subfield('c'),field_format(f.subfield('d'), prefix: ', ').to_s, prefix: ' - (', postfix: ', ...)').to_s).to_s"
222
+ }, {
223
+ title: 'format statement with nested groups',
224
+ input: '([{{($a)}}])',
225
+ tree: {
226
+ entry: [
227
+ {group: {
228
+ prefix: nil, postfix: nil,
229
+ lparen: '(', rparen: ')',
230
+ entry: [
231
+ {group: {
232
+ prefix: nil, postfix: nil,
233
+ lparen: '[', rparen: ']',
234
+ entry: [
235
+ {group: {
236
+ prefix: nil, postfix: nil,
237
+ lparen: '{', rparen: '}',
238
+ entry: [
239
+ {group: {
240
+ prefix: nil, postfix: nil,
241
+ lparen: '{', rparen: '}',
242
+ entry: [
243
+ {group: {
244
+ prefix: nil, postfix: nil,
245
+ lparen: '(', rparen: ')',
246
+ entry: [{subfield: {prefix: nil, repeat: nil, name: 'a'}}]
247
+ }}
248
+ ]
249
+ }}
250
+ ]
251
+ }}
252
+ ]
253
+ }}
254
+ ]
255
+ }}
256
+ ],
257
+ postfix: nil},
258
+ transform: "field_format(field_format(field_format(field_format(field_format(f.subfield('a'), prefix: '(', postfix: ')').to_s, prefix: '{', postfix: '}').to_s, prefix: '{', postfix: '}').to_s, prefix: '[', postfix: ']').to_s, prefix: '(', postfix: ')').to_s"
259
+ }, {
260
+ title: 'format statement with missing closing bracket',
261
+ input: '($a',
262
+ tree: :failure
263
+ }, {
264
+ title: 'format statement with missing opening bracket',
265
+ input: '$a)',
266
+ tree: :failure
267
+ }, {
268
+ title: 'format statement with nested quotes',
269
+ input: ':"-$a, $*"+"b-".',
270
+ tree: {
271
+ entry: [
272
+ {group: {
273
+ prefix: ':', postfix: '-',
274
+ lparen: '"', rparen: '"',
275
+ entry: [
276
+ {subfield: {prefix: '-', repeat: nil, name: 'a'}},
277
+ {subfield: {prefix: ', ', repeat: {separator: '+'}, name: 'b'}}
278
+ ],
279
+ }}
280
+ ],
281
+ postfix: '.'},
282
+ transform: "field_format(field_format(field_format(f.subfield('a'), prefix: '-').to_s,field_format(f.subfield_array('b'), prefix: ', ', join: '+').to_s, prefix: ':\"', postfix: '-\"').to_s, postfix: '.').to_s"
283
+ }, {
284
+ title: 'format statement with double dollar prefix and postfix',
285
+ input: 'ab: $$$*a$$.',
286
+ tree: {
287
+ entry: [{subfield: {prefix: 'ab: $$', repeat: '*', name: 'a'}}],
288
+ postfix: '$$.'},
289
+ transform: "field_format(field_format(f.subfield_array('a'), prefix: 'ab: $$', join: ';').to_s, postfix: '$$.').to_s"
290
+ }, {
291
+ title: 'format statement with condition text',
292
+ input: '$0 =~ /^\(ODIS-(PS|ORG)\) (\d)+$$/',
293
+ tree: {
294
+ entry: [
295
+ {subfield: {prefix: nil, repeat: nil, name: '0'}},
296
+ {group: {
297
+ prefix: ' =~ /^\\', postfix: '\\',
298
+ lparen: '(', rparen: ')',
299
+ entry: [
300
+ {group: {
301
+ prefix: 'ODIS-', postfix: 'PS|ORG',
302
+ lparen: '(', rparen: ')',
303
+ entry: nil
304
+ }}
305
+ ]
306
+ }},
307
+ {group: {
308
+ prefix: ' ', postfix: '\\d',
309
+ lparen: '(', rparen: ')',
310
+ entry: nil
311
+ }}
312
+ ],
313
+ postfix: '+$$/'},
314
+ transform: "field_format(f.subfield('0'),field_format(field_format(, prefix: 'ODIS-(', postfix: 'PS|ORG)').to_s, prefix: ' =~ /^\\(', postfix: '\\)').to_s,field_format(, prefix: ' (', postfix: '\\d)').to_s, postfix: '+$$/').to_s"
315
+ }, {
316
+ title: 'format statement with method call',
317
+ input: '$(my_method($a,$b))',
318
+ tree: {entry: [
319
+ {method_call: {
320
+ prefix: nil, postfix: nil,
321
+ entry: [
322
+ {group: {
323
+ prefix: 'my_method', postfix: nil,
324
+ lparen: '(', rparen: ')',
325
+ entry: [
326
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
327
+ {subfield: {prefix: ',', repeat: nil, name: 'b'}}
328
+ ]
329
+ }}
330
+ ]
331
+ }}
332
+ ],
333
+ postfix: nil},
334
+ transform: {:format => {:entry => [{:method_call => {:prefix => nil, :entry => ["field_format(f.subfield('a'),field_format(f.subfield('b'), prefix: ',').to_s, prefix: 'my_method(', postfix: ')').to_s"], :postfix => nil}}], :postfix => nil}}
335
+ }, {
336
+ title: 'format statement with complex with method call',
337
+ input: "$a $b ($c) ($d) ($g), $(lookup('DOLLAR4','Name','Tag'=>'100','Code'=>$4.to_s)) ($9)",
338
+ tree: {entry: [
339
+ {subfield: {prefix: nil, repeat: nil, name: 'a'}},
340
+ {subfield: {prefix: ' ', repeat: nil, name: 'b'}},
341
+ {group: {
342
+ prefix: ' ', postfix: nil,
343
+ lparen: '(', rparen: ')',
344
+ entry: [{subfield: {prefix: nil, repeat: nil, name: 'c'}}]}},
345
+ {group: {
346
+ prefix: ' ', postfix: nil,
347
+ lparen: '(', rparen: ')',
348
+ entry: [{subfield: {prefix: nil, repeat: nil, name: 'd'}}]
349
+ }},
350
+ {group: {
351
+ prefix: ' ', postfix: nil,
352
+ lparen: '(', rparen: ')',
353
+ entry: [{subfield: {prefix: nil, repeat: nil, name: 'g'}}]
354
+ }},
355
+ {method_call: {
356
+ prefix: ', ', postfix: nil,
357
+ entry: [
358
+ {group: {
359
+ prefix: 'lookup', postfix: '.to_s',
360
+ lparen: '(', rparen: ')',
361
+ entry: [
362
+ {group: {prefix: nil, lparen: "'", entry: nil, postfix: 'DOLLAR4', rparen: "'"}},
363
+ {group: {prefix: ',', lparen: "'", entry: nil, postfix: 'Name', rparen: "'"}},
364
+ {group: {prefix: ',', lparen: "'", entry: nil, postfix: 'Tag', rparen: "'"}},
365
+ {group: {prefix: '=>', lparen: "'", entry: nil, postfix: '100', rparen: "'"}},
366
+ {group: {prefix: ',', lparen: "'", entry: nil, postfix: 'Code', rparen: "'"}},
367
+ {subfield: {prefix: '=>', repeat: nil, name: '4'}}
368
+ ]
369
+ }}
370
+ ]
371
+ }},
372
+ {group: {
373
+ prefix: ' ', postfix: nil,
374
+ lparen: '(', rparen: ')',
375
+ entry: [{subfield: {prefix: nil, repeat: nil, name: '9'}}]
376
+ }}
377
+ ],
378
+ postfix: nil},
379
+ transform: {:format => {:entry => ["f.subfield('a')", "field_format(f.subfield('b'), prefix: ' ').to_s", "field_format(f.subfield('c'), prefix: ' (', postfix: ')').to_s", "field_format(f.subfield('d'), prefix: ' (', postfix: ')').to_s", "field_format(f.subfield('g'), prefix: ' (', postfix: ')').to_s", {:method_call => {:prefix => ', ', :entry => ["field_format(field_format(, prefix: ''', postfix: 'DOLLAR4'').to_s,field_format(, prefix: ','', postfix: 'Name'').to_s,field_format(, prefix: ','', postfix: 'Tag'').to_s,field_format(, prefix: '=>'', postfix: '100'').to_s,field_format(, prefix: ','', postfix: 'Code'').to_s,field_format(f.subfield('4'), prefix: '=>').to_s, prefix: 'lookup(', postfix: '.to_s)').to_s"], :postfix => nil}}, "field_format(f.subfield('9'), prefix: ' (', postfix: ')').to_s"], :postfix => nil}}
380
+ }
381
+ ]
382
+ end