fixy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +6 -1
- data/lib/fixy/formatter/alphanumeric.rb +14 -7
- data/lib/fixy/record.rb +2 -0
- data/lib/fixy/version.rb +1 -1
- data/spec/fixy/record_spec.rb +48 -12
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9262fa93a8633148f73159bacbbcb4d21ed4b408
|
4
|
+
data.tar.gz: 8994b5cd70ce533762cab617358e21f69cf12547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff5b8c0e48810b780fa12ef0eaa2c64c4ca4c7a3a36790808cc31b09d260149e83158eaab624231311e368842b4192d550b1ba176be6fb7e87141faaedaf14d4
|
7
|
+
data.tar.gz: 17ed2f4d5c446805a342181736bcf4e6c1f672b20e8b16b3f184d1c66f6fc4bde028e85ce7e4e439251162ef7931c5f907908799d31fc49c5054061f34a363d6
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -9,15 +9,22 @@ module Fixy
|
|
9
9
|
# left-justified and filled with spaces.
|
10
10
|
#
|
11
11
|
|
12
|
-
def format_alphanumeric(input,
|
13
|
-
|
14
|
-
|
15
|
-
if
|
16
|
-
|
17
|
-
input_string
|
12
|
+
def format_alphanumeric(input, byte_width)
|
13
|
+
result = ''
|
14
|
+
|
15
|
+
if input.bytesize <= byte_width
|
16
|
+
result = input.dup
|
18
17
|
else
|
19
|
-
|
18
|
+
input.each_char do |char|
|
19
|
+
if result.bytesize + char.bytesize <= byte_width
|
20
|
+
result << char
|
21
|
+
else
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
20
25
|
end
|
26
|
+
|
27
|
+
result << " " * (byte_width - result.bytesize)
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
data/lib/fixy/record.rb
CHANGED
data/lib/fixy/version.rb
CHANGED
data/spec/fixy/record_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe 'Defining a Record' do
|
@@ -56,24 +57,47 @@ end
|
|
56
57
|
|
57
58
|
describe 'Generating a Record' do
|
58
59
|
context 'when properly defined' do
|
59
|
-
|
60
|
-
|
61
|
-
include Fixy::Formatter::Alphanumeric
|
60
|
+
class PersonRecordE < Fixy::Record
|
61
|
+
include Fixy::Formatter::Alphanumeric
|
62
62
|
|
63
|
-
|
63
|
+
set_record_length 20
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
field :first_name, 10, '1-10' , :alphanumeric
|
66
|
+
field :last_name , 10, '11-20', :alphanumeric
|
67
67
|
|
68
|
-
|
68
|
+
field_value :first_name, -> { 'Sarah' }
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
end
|
70
|
+
def last_name
|
71
|
+
'Kerrigan'
|
73
72
|
end
|
73
|
+
end
|
74
74
|
|
75
|
+
it 'should generate fixed width record' do
|
75
76
|
PersonRecordE.new.generate.should eq "Sarah Kerrigan \n"
|
76
|
-
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when using the debug flag' do
|
80
|
+
it 'should produce a debug log' do
|
81
|
+
PersonRecordE.new.generate(true).should eq File.read('spec/fixtures/debug_record.txt')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when dealing with multi-byte characters' do
|
87
|
+
it 'should generate fixed width record' do
|
88
|
+
class PersonRecordMultibyte < Fixy::Record
|
89
|
+
include Fixy::Formatter::Alphanumeric
|
90
|
+
|
91
|
+
set_record_length 9
|
92
|
+
|
93
|
+
field :name, 9, '1-9' , :alphanumeric
|
94
|
+
|
95
|
+
field_value :name, -> { "12345678И" }
|
96
|
+
end
|
97
|
+
|
98
|
+
value = PersonRecordMultibyte.new.generate
|
99
|
+
value.should be_valid_encoding
|
100
|
+
value.should == "12345678 \n"
|
77
101
|
end
|
78
102
|
end
|
79
103
|
|
@@ -132,4 +156,16 @@ describe 'Generating a Record' do
|
|
132
156
|
end
|
133
157
|
end
|
134
158
|
end
|
135
|
-
|
159
|
+
|
160
|
+
context 'when a block is passed to field' do
|
161
|
+
class PersonRecordJ < Fixy::Record
|
162
|
+
include Fixy::Formatter::Alphanumeric
|
163
|
+
set_record_length 20
|
164
|
+
field(:description , 20, '1-20', :alphanumeric) { 'Use My Value' }
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'uses the proc conversion as the field value' do
|
168
|
+
PersonRecordJ.new.generate.should eq('Use My Value'.ljust(20) << "\n")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Skalli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-13 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
|
@@ -88,12 +88,12 @@ require_paths:
|
|
88
88
|
- lib
|
89
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- -
|
96
|
+
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|