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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef79a2c068ab89c33c044396d6df49dd63427fe8
4
- data.tar.gz: 2d3dcfbfc0103915d72b7d98bf2d7ea09085f356
3
+ metadata.gz: 79286b082089c1f7ac2a8cd369752b9dfb06eb4e
4
+ data.tar.gz: 7014f16b3fa6e1bd72ef18f8a0cf8982cbaa1f23
5
5
  SHA512:
6
- metadata.gz: 7dbbe596aef26fa2cd0cbd71b1c44bc6b8832537bf77adbe6f1dd7d9fc05b6884daf05eb77e1585253f0c75139208de63a1f2799313f74739f2dc8b7df88ce23
7
- data.tar.gz: 58a1a871fcf95d2b8d3bdcd9d661919df44fb373f8964b58761d5c4849c25e132daa9dbd9f6e394cfba0c4f4d65c180f090fac05ab2118956084a3a8867ec212
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to midos version 0.1.1
5
+ This documentation refers to midos version 0.2.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  email: %q{jens.wille@gmail.com},
14
14
  license: %q{AGPL-3.0},
15
15
  homepage: :blackwinter,
16
- dependencies: %w[nuggets],
16
+ dependencies: { nuggets: '~> 1.4' },
17
17
 
18
18
  required_ruby_version: '>= 1.9.3'
19
19
  }
@@ -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 = 'iso-8859-1'
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, 'w') { |target|
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(file, options = {}, mode = 'r', &block)
86
- encoding = options[:encoding] ||= DEFAULT_ENCODING
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'
@@ -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)
@@ -35,7 +35,7 @@ module Midos
35
35
  class << self
36
36
 
37
37
  def parse(*args, &block)
38
- reader = new(extract_options!(args)).parse(*args, &block)
38
+ reader = new(args.extract_options!).parse(*args, &block)
39
39
  block ? reader : reader.records
40
40
  end
41
41
 
@@ -3,8 +3,8 @@ module Midos
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 1
7
- TINY = 1
6
+ MINOR = 2
7
+ TINY = 0
8
8
 
9
9
  class << self
10
10
 
@@ -37,15 +37,15 @@ module Midos
37
37
  class << self
38
38
 
39
39
  def write(*args, &block)
40
- new(extract_options!(args), &block).write(*args)
40
+ new(args.extract_options!, &block).write(*args)
41
41
  end
42
42
 
43
43
  def write_file(*args, &block)
44
- file_method(:write, 'w', *args, &block)
44
+ file_method(:write, 'wb', *args, &block)
45
45
  end
46
46
 
47
47
  def open(*args, &block)
48
- file_method(nil, 'w', *args, &block)
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!("\n", nl)
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!(args), &block)
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.1.1
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-06-11 00:00:00.000000000 Z
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: '0'
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: '0'
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.1
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.1
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.1.1 [2015-06-11]:
85
+ midos-0.2.0 [2015-10-02]:
86
86
 
87
- * Fixed replacement of special characters in Midos::Reader.
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.1.1)
93
+ - midos Application documentation (v0.2.0)
92
94
  - "--charset"
93
95
  - UTF-8
94
96
  - "--line-numbers"