fixy 0.0.6 → 0.0.7
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.md +4 -0
- data/README.md +6 -0
- data/lib/fixy/record.rb +21 -2
- data/lib/fixy/version.rb +1 -1
- data/spec/fixy/record_spec.rb +27 -0
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3af7502122c5bc3bcc6284ad25a631310925775a
|
4
|
+
data.tar.gz: 2caed3c7e83e9f70bcbb6bde57069021891e21cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c160c295dfb163a34260470a11e1c54fc39c9f9796ca1deef9d19f54637a13c534fa5ebe1155f16363104b36850b579bb6a40ed778f4e245a7d6a40b31d1a35a
|
7
|
+
data.tar.gz: 1348d95b39d809752cbfe47729ec4e6631fdb9bfda256ec6eea955589ab739c157324bfd023504fc1814c334083f4f39c99b1321eb11db2e636a8f58244fb0cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -36,6 +36,7 @@ A fixed-width document (`Fixy::Document`) is composed of multiple single-line re
|
|
36
36
|
Every record is defined through a specific format, which defines the following aspects:
|
37
37
|
|
38
38
|
* Record length (how many characters in the line)
|
39
|
+
* Line ending (optional, defaults to "\n")
|
39
40
|
* Required formatters (e.g. Alphanumeric, Rate, Amount)
|
40
41
|
* Field declaration:
|
41
42
|
* Field human readable name
|
@@ -93,6 +94,11 @@ You can also specify the field definition and field value together by passing a
|
|
93
94
|
|
94
95
|
field(:first_name, 10, '1-10', :alphanumeric) { @first_name }
|
95
96
|
```
|
97
|
+
If a record requires a specific line ending, you can specify it as part of the Record definition.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
set_line_ending Fixy::Record::LINE_ENDING_CRLF
|
101
|
+
```
|
96
102
|
|
97
103
|
Given a record definition, you can generate a single line (e.g. for testing purposes):
|
98
104
|
|
data/lib/fixy/record.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
module Fixy
|
2
2
|
class Record
|
3
|
+
LINE_ENDING_LF = "\n".freeze
|
4
|
+
LINE_ENDING_CR = "\r".freeze
|
5
|
+
LINE_ENDING_CRLF = "#{LINE_ENDING_CR}#{LINE_ENDING_LF}".freeze
|
6
|
+
DEFAULT_LINE_ENDING = LINE_ENDING_LF
|
7
|
+
|
3
8
|
class << self
|
4
9
|
def set_record_length(count)
|
5
10
|
define_singleton_method('record_length') { count }
|
6
11
|
end
|
7
12
|
|
13
|
+
def set_line_ending(character)
|
14
|
+
@line_ending = character
|
15
|
+
end
|
16
|
+
|
8
17
|
def field(name, size, range, type)
|
9
18
|
@record_fields ||= default_record_fields
|
10
19
|
range_matches = range.match /^(\d+)(?:-(\d+))?$/
|
@@ -55,6 +64,11 @@ module Fixy
|
|
55
64
|
@record_fields
|
56
65
|
end
|
57
66
|
|
67
|
+
def line_ending
|
68
|
+
# Use the default line ending unless otherwise specified
|
69
|
+
@line_ending || DEFAULT_LINE_ENDING
|
70
|
+
end
|
71
|
+
|
58
72
|
def default_record_fields
|
59
73
|
if superclass.respond_to?(:record_fields, true) && superclass.record_fields
|
60
74
|
superclass.record_fields.dup
|
@@ -98,7 +112,7 @@ module Fixy
|
|
98
112
|
end
|
99
113
|
|
100
114
|
# Documentation mandates that every record ends with new line.
|
101
|
-
output <<
|
115
|
+
output << line_ending
|
102
116
|
|
103
117
|
{ fields: fields, record: decorator.record(output) }
|
104
118
|
end
|
@@ -128,7 +142,7 @@ module Fixy
|
|
128
142
|
end
|
129
143
|
|
130
144
|
# Documentation mandates that every record ends with new line.
|
131
|
-
output <<
|
145
|
+
output << line_ending
|
132
146
|
|
133
147
|
# All ready. In the words of Mr. Peters: "Take it and go!"
|
134
148
|
decorator.record(output)
|
@@ -145,5 +159,10 @@ module Fixy
|
|
145
159
|
def record_fields
|
146
160
|
self.class.record_fields
|
147
161
|
end
|
162
|
+
|
163
|
+
# Retrieves the line ending for this record type
|
164
|
+
def line_ending
|
165
|
+
self.class.line_ending
|
166
|
+
end
|
148
167
|
end
|
149
168
|
end
|
data/lib/fixy/version.rb
CHANGED
data/spec/fixy/record_spec.rb
CHANGED
@@ -10,6 +10,8 @@ describe 'Defining a Record' do
|
|
10
10
|
|
11
11
|
set_record_length 20
|
12
12
|
|
13
|
+
set_line_ending Fixy::Record::LINE_ENDING_CRLF
|
14
|
+
|
13
15
|
field :first_name, 10, '1-10' , :alphanumeric
|
14
16
|
field :last_name , 10, '11-20', :alphanumeric
|
15
17
|
end
|
@@ -185,6 +187,19 @@ describe 'Generating a Record' do
|
|
185
187
|
PersonRecordJ.new.generate.should eq('Use My Value'.ljust(20) << "\n")
|
186
188
|
end
|
187
189
|
end
|
190
|
+
|
191
|
+
context 'when setting a line ending' do
|
192
|
+
class PersonRecordWithLineEnding < Fixy::Record
|
193
|
+
include Fixy::Formatter::Alphanumeric
|
194
|
+
set_record_length 20
|
195
|
+
set_line_ending Fixy::Record::LINE_ENDING_CRLF
|
196
|
+
field(:description , 20, '1-20', :alphanumeric) { 'Use My Value' }
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'uses the given line ending' do
|
200
|
+
PersonRecordWithLineEnding.new.generate.should eq('Use My Value'.ljust(20) << "\r\n")
|
201
|
+
end
|
202
|
+
end
|
188
203
|
end
|
189
204
|
|
190
205
|
describe 'Parsing a record' do
|
@@ -207,6 +222,18 @@ describe 'Parsing a record' do
|
|
207
222
|
end
|
208
223
|
end
|
209
224
|
|
225
|
+
context 'with custom line endings' do
|
226
|
+
let(:record) { "Use My Value " }
|
227
|
+
it 'should generate fixed width record' do
|
228
|
+
PersonRecordWithLineEnding.parse(record).should eq({
|
229
|
+
record: (record + Fixy::Record::LINE_ENDING_CRLF),
|
230
|
+
fields: [
|
231
|
+
{ name: :description, value: 'Use My Value '}
|
232
|
+
]
|
233
|
+
})
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
210
237
|
context 'when properly defined' do
|
211
238
|
let(:record) { "Sarah Kerrigan " }
|
212
239
|
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2015-05-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
|
@@ -90,17 +90,17 @@ require_paths:
|
|
90
90
|
- lib
|
91
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
requirements:
|
98
|
-
- -
|
98
|
+
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.4.
|
103
|
+
rubygems_version: 2.4.2
|
104
104
|
signing_key:
|
105
105
|
specification_version: 4
|
106
106
|
summary: Provides a DSL for defining, generating, and debugging fixed width documents.
|