bismas 0.3.0 → 0.4.0
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.
- checksums.yaml +4 -4
- data/ChangeLog +7 -0
- data/README +2 -2
- data/lib/bismas.rb +88 -90
- data/lib/bismas/cli.rb +3 -5
- data/lib/bismas/cli/filter.rb +7 -5
- data/lib/bismas/cli/xml.rb +18 -32
- data/lib/bismas/filter.rb +71 -0
- data/lib/bismas/mapping.rb +2 -2
- data/lib/bismas/schema.rb +11 -13
- data/lib/bismas/version.rb +1 -1
- data/lib/bismas/xml.rb +93 -0
- metadata +10 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533b760c35ba8c4d29776069ba3777b33f393769
|
4
|
+
data.tar.gz: e432c79eaa46cdc5f6a2f6d8dc83c63d89062ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c8394bd9f4b7884affa87a4db9aa74ef7d6259c1c72fda722f3d720b70c83afc8831b3d6181fe1a9f0f2c56a801eefcf0e75ba35f40256090f2f530eec68206
|
7
|
+
data.tar.gz: 8ede1a58a6ff0575d756449c70beeaa1ccafcbcf9a8ede32b35e72171b8d24e4a32dfc718df5d4f52d91dea17e65c91ff182755bf637ae8b411a97e3f52da54d
|
data/ChangeLog
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
= Revision history for bismas
|
4
4
|
|
5
|
+
== 0.4.0 [2016-02-02]
|
6
|
+
|
7
|
+
* +bismas2xml+: Include input file's modification time.
|
8
|
+
* +bismas2xml+: Learned options +mapping+, +execute+ and +execute-mapped+.
|
9
|
+
* +bismas-filter+: Accept code file in addition to string for +execute+ and
|
10
|
+
+execute-mapped+ options.
|
11
|
+
|
5
12
|
== 0.3.0 [2015-12-11]
|
6
13
|
|
7
14
|
* Added +bismas2xml+ executable.
|
data/README
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
== VERSION
|
4
4
|
|
5
|
-
This documentation refers to bismas version 0.
|
5
|
+
This documentation refers to bismas version 0.4.0.
|
6
6
|
|
7
7
|
|
8
8
|
== DESCRIPTION
|
@@ -25,7 +25,7 @@ Travis CI:: https://travis-ci.org/blackwinter/bismas
|
|
25
25
|
|
26
26
|
== LICENSE AND COPYRIGHT
|
27
27
|
|
28
|
-
Copyright (C) 2015 Jens Wille
|
28
|
+
Copyright (C) 2015-2016 Jens Wille
|
29
29
|
|
30
30
|
bismas is free software: you can redistribute it and/or modify it
|
31
31
|
under the terms of the GNU Affero General Public License as published by
|
data/lib/bismas.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
module Bismas
|
28
28
|
|
29
|
+
extend self
|
30
|
+
|
29
31
|
# Default file encoding
|
30
32
|
DEFAULT_ENCODING = 'CP850'
|
31
33
|
|
@@ -47,103 +49,99 @@ module Bismas
|
|
47
49
|
# See parameter +FUELLZEICHEN+ in BISMAS <tt>*.CFG</tt>
|
48
50
|
DEFAULT_PADDING_LENGTH = 20
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
end
|
132
|
-
|
133
|
-
def amend_encoding(options, default_encoding = DEFAULT_ENCODING)
|
134
|
-
encoding = (options[:encoding] || default_encoding).to_s
|
135
|
-
|
136
|
-
options[:encoding] = encoding.start_with?(':') ?
|
137
|
-
default_encoding.to_s + encoding : encoding
|
138
|
-
end
|
52
|
+
def chars(options = {})
|
53
|
+
encoding = amend_encoding(options).split(':').last
|
54
|
+
|
55
|
+
Hash[CHARS.map { |k, v| [k, begin
|
56
|
+
v.encode(encoding)
|
57
|
+
rescue Encoding::UndefinedConversionError
|
58
|
+
v.dup.force_encoding(encoding)
|
59
|
+
end] }]
|
60
|
+
end
|
61
|
+
|
62
|
+
def regex(options = {}, chars = chars(options))
|
63
|
+
category_length = options[:category_length] || DEFAULT_CATEGORY_LENGTH
|
64
|
+
|
65
|
+
Hash[REGEX.map { |k, v| [k, Regexp.new(v % chars)] }].update(category:
|
66
|
+
/[^#{chars.values_at(*CATEGORY_CHAR_SKIP).join}]{#{category_length}}/)
|
67
|
+
end
|
68
|
+
|
69
|
+
def filter(klass, options, &block)
|
70
|
+
Filter.run(klass, options, &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_xml(options, &block)
|
74
|
+
XML.run(options, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
def execute(execute, &block)
|
78
|
+
block ||= method(:abort)
|
79
|
+
|
80
|
+
execute.map { |value|
|
81
|
+
value = Array(value).map { |code| case code
|
82
|
+
when /\.rb\z/i then File.readable?(code) ?
|
83
|
+
File.read(code) : block["No such file: #{code}"]
|
84
|
+
when String then code
|
85
|
+
else block["Invalid code: #{code.inspect}"]
|
86
|
+
end }
|
87
|
+
|
88
|
+
lambda { |bind| value.each { |code| eval(code, bind) } }
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def mapping(mapping, &block)
|
93
|
+
block ||= method(:abort)
|
94
|
+
|
95
|
+
Mapping[case mapping
|
96
|
+
when nil, Hash then mapping
|
97
|
+
when /\A\{.*\}\z/ then safe_yaml.load(mapping)
|
98
|
+
when String then File.readable?(mapping) ?
|
99
|
+
safe_yaml.load_file(mapping) : block["No such file: #{mapping}"]
|
100
|
+
else block["Invalid mapping: #{mapping.inspect}"]
|
101
|
+
end]
|
102
|
+
end
|
103
|
+
|
104
|
+
def encode(record, encoding)
|
105
|
+
return record unless encoding
|
106
|
+
|
107
|
+
fallback = Hash.new { |h, k| h[k] = '?' }
|
108
|
+
|
109
|
+
record.each { |key, values|
|
110
|
+
values.each { |value| value.encode!(encoding, fallback: fallback) }
|
111
|
+
|
112
|
+
unless fallback.empty?
|
113
|
+
chars = fallback.keys.map(&:inspect).join(', '); fallback.clear
|
114
|
+
warn "Undefined characters at #{$.}:#{key}: #{chars}"
|
115
|
+
end
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def amend_encoding(options, default_encoding = DEFAULT_ENCODING)
|
120
|
+
encoding = (options[:encoding] || default_encoding).to_s
|
121
|
+
|
122
|
+
options[:encoding] = encoding.start_with?(':') ?
|
123
|
+
default_encoding.to_s + encoding : encoding
|
124
|
+
end
|
125
|
+
|
126
|
+
def require_gem(gem, lib = gem, &block)
|
127
|
+
require lib
|
128
|
+
rescue LoadError => err
|
129
|
+
block ||= method(:abort)
|
130
|
+
block["Please install the `#{gem}' gem. (#{err})"]
|
131
|
+
end
|
139
132
|
|
133
|
+
def safe_yaml
|
134
|
+
require_gem 'safe_yaml', 'safe_yaml/load'
|
135
|
+
SafeYAML
|
140
136
|
end
|
141
137
|
|
142
138
|
end
|
143
139
|
|
140
|
+
require_relative 'bismas/xml'
|
144
141
|
require_relative 'bismas/base'
|
145
142
|
require_relative 'bismas/schema'
|
146
143
|
require_relative 'bismas/reader'
|
147
144
|
require_relative 'bismas/writer'
|
145
|
+
require_relative 'bismas/filter'
|
148
146
|
require_relative 'bismas/mapping'
|
149
147
|
require_relative 'bismas/version'
|
data/lib/bismas/cli.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -39,10 +39,8 @@ module Bismas
|
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
42
|
-
def require_gem(
|
43
|
-
|
44
|
-
rescue LoadError => err
|
45
|
-
abort "Please install the `#{gem}' gem. (#{err})"
|
42
|
+
def require_gem(*args)
|
43
|
+
Bismas.require_gem(*args, &method(:abort))
|
46
44
|
end
|
47
45
|
|
48
46
|
end
|
data/lib/bismas/cli/filter.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -59,6 +59,8 @@ module Bismas
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def opts(opts)
|
62
|
+
opts.summary_width = 34
|
63
|
+
|
62
64
|
opts.option(:input__FILE, 'Path to input file [Default: STDIN]')
|
63
65
|
|
64
66
|
opts.option(:output__FILE, 'Path to output file [Default: STDOUT]')
|
@@ -106,12 +108,12 @@ module Bismas
|
|
106
108
|
|
107
109
|
opts.separator
|
108
110
|
|
109
|
-
opts.option(:
|
110
|
-
options[:execute] << e
|
111
|
+
opts.option(:execute__FILE_OR_CODE, 'Code to execute for each _record_ before mapping') { |e|
|
112
|
+
(options[:execute] ||= []) << e
|
111
113
|
}
|
112
114
|
|
113
|
-
opts.option(:
|
114
|
-
options[:execute_mapped] << e
|
115
|
+
opts.option(:execute_mapped__FILE_OR_CODE, :E, 'Code to execute for each _record_ after mapping') { |e|
|
116
|
+
(options[:execute_mapped] ||= []) << e
|
115
117
|
}
|
116
118
|
|
117
119
|
opts.separator
|
data/lib/bismas/cli/xml.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -31,44 +31,16 @@ module Bismas
|
|
31
31
|
class XML < self
|
32
32
|
|
33
33
|
def run(arguments)
|
34
|
-
require_gem 'builder'
|
35
|
-
|
36
34
|
quit unless arguments.empty?
|
37
35
|
|
38
|
-
|
39
|
-
quit "No such file: #{schema_file}" unless File.readable?(schema_file)
|
40
|
-
|
41
|
-
schema = Schema.parse_file(schema_file)
|
42
|
-
|
43
|
-
reader_options = {
|
44
|
-
encoding: options[:encoding],
|
45
|
-
key: options[:key],
|
46
|
-
strict: options[:strict],
|
47
|
-
silent: options[:silent],
|
48
|
-
category_length: schema.category_length
|
49
|
-
}
|
50
|
-
|
51
|
-
File.open_file(options[:output], {}, 'wb') { |f|
|
52
|
-
xml = Builder::XmlMarkup.new(indent: 2, target: f)
|
53
|
-
xml.instruct!
|
54
|
-
|
55
|
-
xml.records(name: schema.name, description: schema.title) {
|
56
|
-
Reader.parse_file(options[:input], reader_options) { |id, record|
|
57
|
-
xml.record(id: id) {
|
58
|
-
record.sort_by { |key,| key }.each { |key, values|
|
59
|
-
values.each { |value|
|
60
|
-
xml.field(value, name: key, description: schema[key])
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
36
|
+
Bismas.to_xml(options, &method(:quit))
|
67
37
|
end
|
68
38
|
|
69
39
|
private
|
70
40
|
|
71
41
|
def opts(opts)
|
42
|
+
opts.summary_width = 34
|
43
|
+
|
72
44
|
opts.option(:input__FILE, 'Path to input file [Default: STDIN]')
|
73
45
|
|
74
46
|
opts.option(:output__FILE, 'Path to output file [Default: STDOUT]')
|
@@ -85,6 +57,20 @@ module Bismas
|
|
85
57
|
|
86
58
|
opts.separator
|
87
59
|
|
60
|
+
opts.option(:mapping__FILE_OR_YAML, 'Path to mapping file or YAML string')
|
61
|
+
|
62
|
+
opts.separator
|
63
|
+
|
64
|
+
opts.option(:execute__FILE_OR_CODE, 'Code to execute for each _record_ before mapping') { |e|
|
65
|
+
(options[:execute] ||= []) << e
|
66
|
+
}
|
67
|
+
|
68
|
+
opts.option(:execute_mapped__FILE_OR_CODE, :E, 'Code to execute for each _record_ after mapping') { |e|
|
69
|
+
(options[:execute_mapped] ||= []) << e
|
70
|
+
}
|
71
|
+
|
72
|
+
opts.separator
|
73
|
+
|
88
74
|
opts.switch(:strict, :S, 'Turn parse warnings into errors')
|
89
75
|
|
90
76
|
opts.switch(:silent, :T, 'Silence parse warnings')
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# bismas -- A Ruby client for BISMAS databases #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# bismas is free software; you can redistribute it and/or modify it #
|
12
|
+
# under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# bismas is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with bismas. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
module Bismas
|
28
|
+
|
29
|
+
module Filter
|
30
|
+
|
31
|
+
extend self
|
32
|
+
|
33
|
+
extend Bismas
|
34
|
+
|
35
|
+
def run(klass, options, &block)
|
36
|
+
execute = execute(options.values_at(*%i[execute execute_mapped]), &block)
|
37
|
+
mapping = mapping(options[:mapping], &block)
|
38
|
+
|
39
|
+
key_format = options[:key_format]
|
40
|
+
|
41
|
+
writer_options = {
|
42
|
+
encoding: encoding = options[:output_encoding],
|
43
|
+
key: options[:output_key],
|
44
|
+
sort: options[:sort],
|
45
|
+
padding_length: options[:padding_length],
|
46
|
+
category_length: options[:category_length]
|
47
|
+
}
|
48
|
+
|
49
|
+
reader_options = {
|
50
|
+
encoding: options[:input_encoding],
|
51
|
+
key: options[:input_key],
|
52
|
+
strict: options[:strict],
|
53
|
+
silent: options[:silent],
|
54
|
+
legacy: options[:legacy],
|
55
|
+
category_length: options[:category_length]
|
56
|
+
}
|
57
|
+
|
58
|
+
klass.open(options[:output], writer_options) { |writer|
|
59
|
+
Reader.parse_file(options[:input], reader_options) { |id, record|
|
60
|
+
execute[0][bind = binding]
|
61
|
+
record = mapping.apply(encode(record, encoding))
|
62
|
+
|
63
|
+
execute[1][bind]
|
64
|
+
writer[key_format % id] = record
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/lib/bismas/mapping.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -53,7 +53,7 @@ module Bismas
|
|
53
53
|
|
54
54
|
def apply(hash, new_hash = default_hash)
|
55
55
|
hash.each { |key, value| map(key) { |new_key|
|
56
|
-
new_hash[new_key].concat(value)
|
56
|
+
new_hash[new_key].concat(Array(value))
|
57
57
|
} }
|
58
58
|
|
59
59
|
new_hash
|
data/lib/bismas/schema.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# #
|
4
4
|
# bismas -- A Ruby client for BISMAS databases #
|
5
5
|
# #
|
6
|
-
# Copyright (C) 2015 Jens Wille
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
7
|
# #
|
8
8
|
# Authors: #
|
9
9
|
# Jens Wille <jens.wille@gmail.com> #
|
@@ -24,10 +24,16 @@
|
|
24
24
|
###############################################################################
|
25
25
|
#++
|
26
26
|
|
27
|
+
require 'forwardable'
|
28
|
+
|
27
29
|
module Bismas
|
28
30
|
|
29
31
|
class Schema
|
30
32
|
|
33
|
+
include Enumerable
|
34
|
+
|
35
|
+
extend Forwardable
|
36
|
+
|
31
37
|
FIELD_RE = %r{\Afeld\s+=\s+(\d+)}i
|
32
38
|
|
33
39
|
CATEGORY_RE = lambda { |category_length|
|
@@ -52,6 +58,10 @@ module Bismas
|
|
52
58
|
|
53
59
|
attr_accessor :title, :name, :category_length
|
54
60
|
|
61
|
+
def_delegators :@categories, :[], :[]=, :each
|
62
|
+
|
63
|
+
def_delegator :@categories, :keys, :categories
|
64
|
+
|
55
65
|
def parse(io)
|
56
66
|
category_re = nil
|
57
67
|
|
@@ -72,18 +82,6 @@ module Bismas
|
|
72
82
|
self
|
73
83
|
end
|
74
84
|
|
75
|
-
def categories
|
76
|
-
@categories.keys
|
77
|
-
end
|
78
|
-
|
79
|
-
def [](key)
|
80
|
-
@categories[key]
|
81
|
-
end
|
82
|
-
|
83
|
-
def []=(key, value)
|
84
|
-
@categories[key] = value
|
85
|
-
end
|
86
|
-
|
87
85
|
end
|
88
86
|
|
89
87
|
end
|
data/lib/bismas/version.rb
CHANGED
data/lib/bismas/xml.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
#--
|
2
|
+
###############################################################################
|
3
|
+
# #
|
4
|
+
# bismas -- A Ruby client for BISMAS databases #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2015-2016 Jens Wille #
|
7
|
+
# #
|
8
|
+
# Authors: #
|
9
|
+
# Jens Wille <jens.wille@gmail.com> #
|
10
|
+
# #
|
11
|
+
# bismas is free software; you can redistribute it and/or modify it #
|
12
|
+
# under the terms of the GNU Affero General Public License as published by #
|
13
|
+
# the Free Software Foundation; either version 3 of the License, or (at your #
|
14
|
+
# option) any later version. #
|
15
|
+
# #
|
16
|
+
# bismas is distributed in the hope that it will be useful, but #
|
17
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
|
18
|
+
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public #
|
19
|
+
# License for more details. #
|
20
|
+
# #
|
21
|
+
# You should have received a copy of the GNU Affero General Public License #
|
22
|
+
# along with bismas. If not, see <http://www.gnu.org/licenses/>. #
|
23
|
+
# #
|
24
|
+
###############################################################################
|
25
|
+
#++
|
26
|
+
|
27
|
+
require 'time'
|
28
|
+
|
29
|
+
module Bismas
|
30
|
+
|
31
|
+
module XML
|
32
|
+
|
33
|
+
extend self
|
34
|
+
|
35
|
+
extend Bismas
|
36
|
+
|
37
|
+
def run(options, &block)
|
38
|
+
block ||= method(:abort)
|
39
|
+
|
40
|
+
require_gem 'builder'
|
41
|
+
|
42
|
+
block['Schema file is required'] unless schema_file = options[:schema]
|
43
|
+
block["No such file: #{schema_file}"] unless File.readable?(schema_file)
|
44
|
+
|
45
|
+
schema = Schema.parse_file(schema_file)
|
46
|
+
|
47
|
+
execute = execute(options.values_at(*%i[execute execute_mapped]), &block)
|
48
|
+
mapping = mapping(options[:mapping], &block)
|
49
|
+
|
50
|
+
records_attributes = {
|
51
|
+
name: schema.name,
|
52
|
+
description: schema.title,
|
53
|
+
mtime: File.mtime(options[:input]).xmlschema
|
54
|
+
}
|
55
|
+
|
56
|
+
reader_options = {
|
57
|
+
encoding: options[:encoding],
|
58
|
+
key: options[:key],
|
59
|
+
strict: options[:strict],
|
60
|
+
silent: options[:silent],
|
61
|
+
category_length: schema.category_length
|
62
|
+
}
|
63
|
+
|
64
|
+
schema = mapping.apply(schema)
|
65
|
+
|
66
|
+
File.open_file(options[:output], {}, 'wb') { |f|
|
67
|
+
xml = Builder::XmlMarkup.new(indent: 2, target: f)
|
68
|
+
xml.instruct!
|
69
|
+
|
70
|
+
xml.records(records_attributes) {
|
71
|
+
Reader.parse_file(options[:input], reader_options) { |id, record|
|
72
|
+
xml.record(id: id) {
|
73
|
+
execute[0][bind = binding]
|
74
|
+
record = mapping.apply(record)
|
75
|
+
|
76
|
+
execute[1][bind]
|
77
|
+
record.sort_by { |key,| key }.each { |key, values|
|
78
|
+
field_attributes = {
|
79
|
+
name: key,
|
80
|
+
description: Array(schema[key]).join('/')
|
81
|
+
}
|
82
|
+
|
83
|
+
Array(values).each { |value| xml.field(value, field_attributes) }
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bismas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Wille
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cyclops
|
@@ -111,12 +111,14 @@ files:
|
|
111
111
|
- lib/bismas/cli/chardiff.rb
|
112
112
|
- lib/bismas/cli/filter.rb
|
113
113
|
- lib/bismas/cli/xml.rb
|
114
|
+
- lib/bismas/filter.rb
|
114
115
|
- lib/bismas/mapping.rb
|
115
116
|
- lib/bismas/parser.rb
|
116
117
|
- lib/bismas/reader.rb
|
117
118
|
- lib/bismas/schema.rb
|
118
119
|
- lib/bismas/version.rb
|
119
120
|
- lib/bismas/writer.rb
|
121
|
+
- lib/bismas/xml.rb
|
120
122
|
- spec/bismas/parser_spec.rb
|
121
123
|
- spec/bismas/reader_spec.rb
|
122
124
|
- spec/bismas/schema_spec.rb
|
@@ -129,19 +131,16 @@ licenses:
|
|
129
131
|
metadata: {}
|
130
132
|
post_install_message: |2+
|
131
133
|
|
132
|
-
bismas-0.
|
134
|
+
bismas-0.4.0 [2016-02-02]:
|
133
135
|
|
134
|
-
*
|
135
|
-
*
|
136
|
-
*
|
137
|
-
|
138
|
-
* Fixed Bismas.amend_encoding to use default encoding when encoding option is
|
139
|
-
+nil+.
|
140
|
-
* Changed Bismas::Writer to insert key field at beginning of record.
|
136
|
+
* +bismas2xml+: Include input file's modification time.
|
137
|
+
* +bismas2xml+: Learned options +mapping+, +execute+ and +execute-mapped+.
|
138
|
+
* +bismas-filter+: Accept code file in addition to string for +execute+ and
|
139
|
+
+execute-mapped+ options.
|
141
140
|
|
142
141
|
rdoc_options:
|
143
142
|
- "--title"
|
144
|
-
- bismas Application documentation (v0.
|
143
|
+
- bismas Application documentation (v0.4.0)
|
145
144
|
- "--charset"
|
146
145
|
- UTF-8
|
147
146
|
- "--line-numbers"
|