fixy 0.0.5 → 0.0.6

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: a3d8c35cccf39e65c7ceeeebc7d3cc3d2e08296a
4
- data.tar.gz: dbb83894c29fccf2b036fa4658af9987d849b541
3
+ metadata.gz: d897c37235240b3fc2a84c136fcd3cc0bcb77040
4
+ data.tar.gz: f71f5072d0b9eadc315ee23d06326d97c39ec987
5
5
  SHA512:
6
- metadata.gz: 3677b88c7b380b05154131b4db1298ac86fe3b7db5baeef25e7664ed757e9206a7861ffcd023b7a04ba672479bc35fb4508761227e8f0e332f2eecb6ecf8036a
7
- data.tar.gz: 9d474b78d20ca903a8a618b8a7a8002f128308268cdc4e14d09bdb980094571ff9f5b95cc4c061d64f8a075a30d5dd239cbb2ef52f05a240bfca42a016ec6c3f
6
+ metadata.gz: 0b5c8b72616560961fe6bcfcadce4f5422a1801731190c74c4f94b97df8399665051005159132c4cb5371ae0c839177814c5339984dcb0a2e2d54f839c425e40
7
+ data.tar.gz: 4068c6f9b3d9fd9aabfc0120de7d818a3a49f4099f26acfeda0bf9d799fcf424ca3f6111f8c254a2a7ad8f5303f7a82331ff43c277587b25237f520569608bbd
@@ -1,3 +1,7 @@
1
+ ## v0.0.6
2
+
3
+ * Support for multi-byte record parsing
4
+
1
5
  ## v0.0.5
2
6
 
3
7
  * Allow nil values for alphanumeric formatter
@@ -67,7 +67,7 @@ module Fixy
67
67
  def parse(record, debug = false)
68
68
  raise ArgumentError, 'Record must be a string' unless record.is_a? String
69
69
 
70
- unless record.length == record_length
70
+ unless record.bytesize == record_length
71
71
  raise ArgumentError, "Record length is invalid (Expected #{record_length})"
72
72
  end
73
73
 
@@ -77,6 +77,7 @@ module Fixy
77
77
  current_position = 1
78
78
  current_record = 1
79
79
 
80
+ byte_record = record.bytes.to_a
80
81
  while current_position <= record_length do
81
82
 
82
83
  field = record_fields[current_position]
@@ -86,7 +87,7 @@ module Fixy
86
87
  from = field[:from] - 1
87
88
  to = field[:to] - 1
88
89
  method = field[:name]
89
- value = record[from..to]
90
+ value = byte_record[from..to].pack('C*').force_encoding('utf-8')
90
91
 
91
92
  formatted_value = decorator.field(value, current_record, current_position, method, field[:size], field[:type])
92
93
  output << formatted_value
@@ -1,3 +1,3 @@
1
1
  module Fixy
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -0,0 +1,2 @@
1
+ <div><pre><span class='odd' data-column='1' data-method='first_name' data-size='10' data-format='alphanumeric'>älimuk </span><span class='even' data-column='11' data-method='last_name' data-size='10' data-format='alphanumeric'>Karil </span>
2
+ </pre></div>
@@ -188,6 +188,25 @@ describe 'Generating a Record' do
188
188
  end
189
189
 
190
190
  describe 'Parsing a record' do
191
+ let(:multibyte_record) { 'älimuk Karil ' }
192
+ context 'with a record of multi-byte characters' do
193
+ it 'should not raise with the right number of bytes' do
194
+ PersonRecordE.parse(multibyte_record, true).should eq({
195
+ record: File.read('spec/fixtures/debug_parsed_multibyte_record.txt'),
196
+ fields: [
197
+ { name: :first_name, value: 'älimuk '},
198
+ { name: :last_name, value: 'Karil '}
199
+ ]
200
+ })
201
+ end
202
+
203
+ it 'should not raise with the right amount' do
204
+ expect {
205
+ PersonRecordE.parse('älimuk Karil ', true)
206
+ }.to raise_error(StandardError, 'Record length is invalid (Expected 20)')
207
+ end
208
+ end
209
+
191
210
  context 'when properly defined' do
192
211
  let(:record) { "Sarah Kerrigan " }
193
212
  class PersonRecordK < Fixy::Record
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Skalli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-01 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Library for generating fixed width flat files.
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
62
+ - .gitignore
63
63
  - CHANGELOG.md
64
64
  - Gemfile
65
65
  - LICENSE.txt
@@ -74,6 +74,7 @@ files:
74
74
  - lib/fixy/record.rb
75
75
  - lib/fixy/version.rb
76
76
  - spec/fixtures/debug_document.txt
77
+ - spec/fixtures/debug_parsed_multibyte_record.txt
77
78
  - spec/fixtures/debug_parsed_record.txt
78
79
  - spec/fixtures/debug_record.txt
79
80
  - spec/fixy/document_spec.rb
@@ -89,22 +90,23 @@ require_paths:
89
90
  - lib
90
91
  required_ruby_version: !ruby/object:Gem::Requirement
91
92
  requirements:
92
- - - ">="
93
+ - - '>='
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  requirements:
97
- - - ">="
98
+ - - '>='
98
99
  - !ruby/object:Gem::Version
99
100
  version: '0'
100
101
  requirements: []
101
102
  rubyforge_project:
102
- rubygems_version: 2.4.2
103
+ rubygems_version: 2.4.4
103
104
  signing_key:
104
105
  specification_version: 4
105
106
  summary: Provides a DSL for defining, generating, and debugging fixed width documents.
106
107
  test_files:
107
108
  - spec/fixtures/debug_document.txt
109
+ - spec/fixtures/debug_parsed_multibyte_record.txt
108
110
  - spec/fixtures/debug_parsed_record.txt
109
111
  - spec/fixtures/debug_record.txt
110
112
  - spec/fixy/document_spec.rb