midos 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/README +1 -1
- data/Rakefile +1 -1
- data/lib/midos.rb +8 -13
- data/lib/midos/base.rb +2 -4
- data/lib/midos/reader.rb +1 -1
- data/lib/midos/version.rb +2 -2
- data/lib/midos/writer.rb +15 -6
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79286b082089c1f7ac2a8cd369752b9dfb06eb4e
|
4
|
+
data.tar.gz: 7014f16b3fa6e1bd72ef18f8a0cf8982cbaa1f23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0703932d02f3414ea401e6fb0e3873ff240dab5a4287c69e3504d116735a110145f44409abcf49b9f155cacb4243470136026b428a70944c3ac0ee9529a993c
|
7
|
+
data.tar.gz: 4850fb5181fb670af4615a8b793db0bb96b905d76a5d41700f8d1fa52ce68f57464d05f07d9dbf9da9e86cc3948c2dc2bf9def3c70572bd4923c62b38e605c20
|
data/ChangeLog
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
= Revision history for midos
|
4
4
|
|
5
|
+
== 0.2.0 [2015-10-02]
|
6
|
+
|
7
|
+
* Added +sort+ option to Midos::Writer.
|
8
|
+
* Added Midos::Writer#[]= convenience method.
|
9
|
+
* Fixed Midos::Writer.transform to recognize any combination of CR/LF.
|
10
|
+
|
5
11
|
== 0.1.1 [2015-06-11]
|
6
12
|
|
7
13
|
* Fixed replacement of special characters in Midos::Reader.
|
data/README
CHANGED
data/Rakefile
CHANGED
data/lib/midos.rb
CHANGED
@@ -26,6 +26,8 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
+
require 'nuggets/file/open_file'
|
30
|
+
|
29
31
|
module Midos
|
30
32
|
|
31
33
|
# Record separator
|
@@ -44,7 +46,7 @@ module Midos
|
|
44
46
|
DEFAULT_LE = "\r\n"
|
45
47
|
|
46
48
|
# Default file encoding
|
47
|
-
DEFAULT_ENCODING = '
|
49
|
+
DEFAULT_ENCODING = 'ISO-8859-1'
|
48
50
|
|
49
51
|
class << self
|
50
52
|
|
@@ -60,7 +62,7 @@ module Midos
|
|
60
62
|
|
61
63
|
def filter_file(source_file, target_file, source_options = {}, target_options = source_options, &block)
|
62
64
|
open_file(source_file, source_options) { |source|
|
63
|
-
open_file(target_file, target_options, '
|
65
|
+
open_file(target_file, target_options, 'wb') { |target|
|
64
66
|
filter(source, target, source_options, target_options, &block)
|
65
67
|
}
|
66
68
|
}
|
@@ -82,17 +84,9 @@ module Midos
|
|
82
84
|
uniq_wrapper { |block| filter_file(*args, &block) }
|
83
85
|
end
|
84
86
|
|
85
|
-
def open_file(
|
86
|
-
|
87
|
-
|
88
|
-
if file =~ /\.gz\z/i
|
89
|
-
require 'zlib'
|
90
|
-
|
91
|
-
gzip = mode.include?('w') ? Zlib::GzipWriter : Zlib::GzipReader
|
92
|
-
gzip.open(file, encoding: encoding, &block)
|
93
|
-
else
|
94
|
-
File.open(file, mode, encoding: encoding, &block)
|
95
|
-
end
|
87
|
+
def open_file(filename, options = {}, mode = 'rb', &block)
|
88
|
+
options[:encoding] ||= DEFAULT_ENCODING
|
89
|
+
File.open_file(filename, options, mode, &block)
|
96
90
|
end
|
97
91
|
|
98
92
|
private
|
@@ -111,3 +105,4 @@ end
|
|
111
105
|
require_relative 'midos/base'
|
112
106
|
require_relative 'midos/reader'
|
113
107
|
require_relative 'midos/writer'
|
108
|
+
require_relative 'midos/version'
|
data/lib/midos/base.rb
CHANGED
@@ -26,6 +26,8 @@
|
|
26
26
|
###############################################################################
|
27
27
|
#++
|
28
28
|
|
29
|
+
require 'nuggets/array/extract_options'
|
30
|
+
|
29
31
|
module Midos
|
30
32
|
|
31
33
|
class Base
|
@@ -45,10 +47,6 @@ module Midos
|
|
45
47
|
args.map { |a| "%#{a.bytes.map { |b| b.to_s(16) }.join.upcase}" }
|
46
48
|
end
|
47
49
|
|
48
|
-
def extract_options!(args)
|
49
|
-
args.last.is_a?(Hash) ? args.pop : {}
|
50
|
-
end
|
51
|
-
|
52
50
|
end
|
53
51
|
|
54
52
|
def initialize(options = {}, &block)
|
data/lib/midos/reader.rb
CHANGED
data/lib/midos/version.rb
CHANGED
data/lib/midos/writer.rb
CHANGED
@@ -37,15 +37,15 @@ module Midos
|
|
37
37
|
class << self
|
38
38
|
|
39
39
|
def write(*args, &block)
|
40
|
-
new(extract_options
|
40
|
+
new(args.extract_options!, &block).write(*args)
|
41
41
|
end
|
42
42
|
|
43
43
|
def write_file(*args, &block)
|
44
|
-
file_method(:write, '
|
44
|
+
file_method(:write, 'wb', *args, &block)
|
45
45
|
end
|
46
46
|
|
47
47
|
def open(*args, &block)
|
48
|
-
file_method(nil, '
|
48
|
+
file_method(nil, 'wb', *args, &block)
|
49
49
|
end
|
50
50
|
|
51
51
|
def transform(value, vs, nl)
|
@@ -56,13 +56,18 @@ module Midos
|
|
56
56
|
value.map { |v| v.gsub(vs, rvs) }.join(vs)
|
57
57
|
|
58
58
|
value.gsub!(nl, rnl)
|
59
|
-
value.gsub!(
|
59
|
+
value.gsub!(/\r\n?|\n/, nl)
|
60
60
|
|
61
61
|
value
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
+
def initialize(options = {})
|
67
|
+
@sort = options[:sort]
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
66
71
|
def vs=(vs)
|
67
72
|
vs.is_a?(String) ? @vs = vs : raise(TypeError,
|
68
73
|
"wrong argument type #{vs.class} (expected String)")
|
@@ -86,6 +91,10 @@ module Midos
|
|
86
91
|
|
87
92
|
alias_method :<<, :put
|
88
93
|
|
94
|
+
def []=(id, record)
|
95
|
+
write_i(id, record)
|
96
|
+
end
|
97
|
+
|
89
98
|
private
|
90
99
|
|
91
100
|
def write_i(id, record, io = io())
|
@@ -93,7 +102,7 @@ module Midos
|
|
93
102
|
|
94
103
|
record[key] = id || auto_id.call if key && !record.key?(key)
|
95
104
|
|
96
|
-
record.each { |k, v|
|
105
|
+
(@sort ? Hash[record.sort] : record).each { |k, v|
|
97
106
|
k ? io << k << fs << transform(v) << le :
|
98
107
|
Array(v).each { |w| io << w.to_s << le } if v
|
99
108
|
}
|
@@ -159,7 +168,7 @@ module Midos
|
|
159
168
|
class << self
|
160
169
|
|
161
170
|
def write(*args, &block)
|
162
|
-
new(extract_options
|
171
|
+
new(args.extract_options!, &block)
|
163
172
|
.instruct! { |mth| mth.write(*args) }
|
164
173
|
end
|
165
174
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nuggets
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hen
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0.8'
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.8.
|
36
|
+
version: 0.8.3
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0.8'
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.8.
|
46
|
+
version: 0.8.3
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,13 +82,15 @@ licenses:
|
|
82
82
|
metadata: {}
|
83
83
|
post_install_message: |2+
|
84
84
|
|
85
|
-
midos-0.
|
85
|
+
midos-0.2.0 [2015-10-02]:
|
86
86
|
|
87
|
-
*
|
87
|
+
* Added +sort+ option to Midos::Writer.
|
88
|
+
* Added Midos::Writer#[]= convenience method.
|
89
|
+
* Fixed Midos::Writer.transform to recognize any combination of CR/LF.
|
88
90
|
|
89
91
|
rdoc_options:
|
90
92
|
- "--title"
|
91
|
-
- midos Application documentation (v0.
|
93
|
+
- midos Application documentation (v0.2.0)
|
92
94
|
- "--charset"
|
93
95
|
- UTF-8
|
94
96
|
- "--line-numbers"
|