flat 0.1.1 → 0.1.2
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/flat.gemspec +2 -1
- data/lib/flat/version.rb +1 -1
- metadata +3 -24
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -14
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -15
- data/Gemfile +0 -4
- data/Guardfile +0 -5
- data/Rakefile +0 -18
- data/spec/flat_file_helper.rb +0 -27
- data/spec/lib/flat/field_spec.rb +0 -126
- data/spec/lib/flat/file_data_spec.rb +0 -46
- data/spec/lib/flat/file_spec.rb +0 -5
- data/spec/lib/flat/record_spec.rb +0 -40
- data/spec/lib/flat_spec.rb +0 -28
- data/spec/spec_helper.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a5de78be3005078ab631ac84a51aadf0e052925
|
|
4
|
+
data.tar.gz: 1360042ad4aa5b1179f4e5064bd9c7509c7a97d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7726ead08345447649093a88350019d001448006a82f48218ac1c9897b857533442b520b8f99bc98bf8cce2c7ee0a73f171cb3a88773f42d5f9f507f9b85b36a
|
|
7
|
+
data.tar.gz: 815db149f73d0a3f373441acd8c70b68b01b019127823ae8bf2ffc60683e8b30390b2b747f9da258f3f4a9e2fd2db84dad664ddb8cac193b4361747a118dc33e
|
data/flat.gemspec
CHANGED
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
|
13
13
|
spec.homepage = "https://github.com/juicyparts/flat"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |name| name.match(/^\.|^G.*|^Rakefile$|^spec.*/) }
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
"source_code" => 'https://github.com/juicyparts/flat',
|
|
26
26
|
"documentation" => 'http://rubydoc.info/github/juicyparts/flat',
|
|
27
27
|
"issue_tracker" => "https://github.com/juicyparts/flat/issues",
|
|
28
|
+
"wiki" => "https://github.com/juicyparts/flat/wiki",
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
spec.add_runtime_dependency "extlib", "~> 0.9.0"
|
data/lib/flat/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mel Riffe
|
|
@@ -186,16 +186,8 @@ executables: []
|
|
|
186
186
|
extensions: []
|
|
187
187
|
extra_rdoc_files: []
|
|
188
188
|
files:
|
|
189
|
-
- ".coveralls.yml"
|
|
190
|
-
- ".gitignore"
|
|
191
|
-
- ".ruby-gemset"
|
|
192
|
-
- ".ruby-version"
|
|
193
|
-
- ".travis.yml"
|
|
194
|
-
- Gemfile
|
|
195
|
-
- Guardfile
|
|
196
189
|
- LICENSE.txt
|
|
197
190
|
- README.md
|
|
198
|
-
- Rakefile
|
|
199
191
|
- flat.gemspec
|
|
200
192
|
- lib/flat.rb
|
|
201
193
|
- lib/flat/errors.rb
|
|
@@ -206,13 +198,6 @@ files:
|
|
|
206
198
|
- lib/flat/read_operations.rb
|
|
207
199
|
- lib/flat/record.rb
|
|
208
200
|
- lib/flat/version.rb
|
|
209
|
-
- spec/flat_file_helper.rb
|
|
210
|
-
- spec/lib/flat/field_spec.rb
|
|
211
|
-
- spec/lib/flat/file_data_spec.rb
|
|
212
|
-
- spec/lib/flat/file_spec.rb
|
|
213
|
-
- spec/lib/flat/record_spec.rb
|
|
214
|
-
- spec/lib/flat_spec.rb
|
|
215
|
-
- spec/spec_helper.rb
|
|
216
201
|
homepage: https://github.com/juicyparts/flat
|
|
217
202
|
licenses:
|
|
218
203
|
- MIT
|
|
@@ -220,6 +205,7 @@ metadata:
|
|
|
220
205
|
source_code: https://github.com/juicyparts/flat
|
|
221
206
|
documentation: http://rubydoc.info/github/juicyparts/flat
|
|
222
207
|
issue_tracker: https://github.com/juicyparts/flat/issues
|
|
208
|
+
wiki: https://github.com/juicyparts/flat/wiki
|
|
223
209
|
post_install_message: Thanks for installing!
|
|
224
210
|
rdoc_options: []
|
|
225
211
|
require_paths:
|
|
@@ -240,11 +226,4 @@ rubygems_version: 2.4.1
|
|
|
240
226
|
signing_key:
|
|
241
227
|
specification_version: 4
|
|
242
228
|
summary: Library to make processing Flat Flies as easy as CSV files.
|
|
243
|
-
test_files:
|
|
244
|
-
- spec/flat_file_helper.rb
|
|
245
|
-
- spec/lib/flat/field_spec.rb
|
|
246
|
-
- spec/lib/flat/file_data_spec.rb
|
|
247
|
-
- spec/lib/flat/file_spec.rb
|
|
248
|
-
- spec/lib/flat/record_spec.rb
|
|
249
|
-
- spec/lib/flat_spec.rb
|
|
250
|
-
- spec/spec_helper.rb
|
|
229
|
+
test_files: []
|
data/.coveralls.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
service_name: travis-ci
|
data/.gitignore
DELETED
data/.ruby-gemset
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
flat
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.1.2
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Guardfile
DELETED
data/Rakefile
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'rspec/core/rake_task'
|
|
2
|
-
require 'bundler/gem_tasks'
|
|
3
|
-
require 'rdoc/task'
|
|
4
|
-
|
|
5
|
-
# Default directory to look in is `/specs`
|
|
6
|
-
# Run with `rake spec`
|
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
|
8
|
-
task.rspec_opts = ['--color', '--format', 'documentation']
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
task :default => :spec
|
|
12
|
-
|
|
13
|
-
RDoc::Task.new(:rdoc => "doc", :clobber_rdoc => "doc:clean", :rerdoc => "doc:force") do |rdoc|
|
|
14
|
-
rdoc.rdoc_dir = 'doc'
|
|
15
|
-
rdoc.title = 'Flat Library Documentation'
|
|
16
|
-
rdoc.main = "README.md"
|
|
17
|
-
rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
|
|
18
|
-
end
|
data/spec/flat_file_helper.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# This file contains Flat::File definitions that can be used to test the
|
|
2
|
-
# various features and functions of Flat.
|
|
3
|
-
|
|
4
|
-
class PersonFile < Flat::File
|
|
5
|
-
|
|
6
|
-
EXAMPLE_FILE = <<-EOF
|
|
7
|
-
1234567890123456789012345678901234567890
|
|
8
|
-
f_name l_name age pad---
|
|
9
|
-
Captain Stubing 4 xxx
|
|
10
|
-
No Phone 5 xxx
|
|
11
|
-
Has Phone 11111111116 xxx
|
|
12
|
-
|
|
13
|
-
EOF
|
|
14
|
-
|
|
15
|
-
add_field :f_name, :width => 10
|
|
16
|
-
|
|
17
|
-
add_field :l_name, :width => 10, :aggressive => true
|
|
18
|
-
|
|
19
|
-
add_field :phone, :width => 10
|
|
20
|
-
|
|
21
|
-
add_field :age, :width => 4, :filter => proc { |v| v.to_i }, :formatter => proc { |v| v.to_f.to_s }
|
|
22
|
-
|
|
23
|
-
pad :auto_name, :width => 3
|
|
24
|
-
|
|
25
|
-
add_field :ignore, :width => 3, :padding => true
|
|
26
|
-
|
|
27
|
-
end
|
data/spec/lib/flat/field_spec.rb
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Field do
|
|
4
|
-
|
|
5
|
-
let(:flat_file) { Flat::File }
|
|
6
|
-
|
|
7
|
-
describe Field::Definition do
|
|
8
|
-
describe 'instance creation' do
|
|
9
|
-
it 'should add a new field definition given minimum required information' do
|
|
10
|
-
# Minimum required fields are not enforced, just 'nice to have'.
|
|
11
|
-
field = flat_file.add_field :name, width: 5
|
|
12
|
-
expect( field ).to be_an_instance_of( Field::Definition )
|
|
13
|
-
expect( field.parent ).to eq( flat_file )
|
|
14
|
-
expect( field.name ).to eq( :name )
|
|
15
|
-
expect( field.width ).to eq( 5 )
|
|
16
|
-
expect( field.padding? ).to be false
|
|
17
|
-
expect( field.aggressive? ).to be false
|
|
18
|
-
expect( field.filters ).to be_empty
|
|
19
|
-
expect( field.formatters ).to be_empty
|
|
20
|
-
expect( field.map_in_proc ).to be_nil
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end # => describe Field::Definition
|
|
24
|
-
|
|
25
|
-
describe 'add_field' do
|
|
26
|
-
before do
|
|
27
|
-
flat_file.reset_file_data
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'adds 1 field to flat file' do
|
|
31
|
-
flat_file.add_field :test, width: 20
|
|
32
|
-
expect( flat_file.fields.size ).to eq( 1 )
|
|
33
|
-
expect( flat_file.width ).to eq( 20 )
|
|
34
|
-
expect( flat_file.pack_format ).to eq( 'A20' )
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'adds 2 fields to flat file' do
|
|
38
|
-
flat_file.add_field :test, width: 17
|
|
39
|
-
flat_file.add_field :test, width: 23
|
|
40
|
-
expect( flat_file.fields.size ).to eq( 2 )
|
|
41
|
-
expect( flat_file.width ).to eq( 40 )
|
|
42
|
-
expect( flat_file.pack_format ).to eq( 'A17A23' )
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'adds a field via a block' do
|
|
46
|
-
# Method A: specifying field name inside the block
|
|
47
|
-
flat_file.add_field do |field|
|
|
48
|
-
field.name = :test
|
|
49
|
-
field.width = 15
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Method B: specifying field name outside the block
|
|
53
|
-
flat_file.add_field :test2 do |field|
|
|
54
|
-
field.width = 15
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
field = flat_file.fields.last
|
|
58
|
-
expect( field.name ).to eq( :test2 )
|
|
59
|
-
|
|
60
|
-
expect( flat_file.fields.size ).to eq( 2)
|
|
61
|
-
expect( flat_file.width ).to eq( 30 )
|
|
62
|
-
expect( flat_file.pack_format ).to eq( 'A15A15' )
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe 'pad' do
|
|
67
|
-
before do
|
|
68
|
-
flat_file.reset_file_data
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'adds a named pad field to flat file' do
|
|
72
|
-
field = flat_file.pad :test, width: 12
|
|
73
|
-
expect( field.padding? ).to be true
|
|
74
|
-
expect( field.name ).to eq( :test )
|
|
75
|
-
expect( flat_file.fields.size ).to eq( 1 )
|
|
76
|
-
expect( flat_file.width ).to eq( 12 )
|
|
77
|
-
expect( flat_file.pack_format ).to eq( 'A12' )
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'adds an auto named pad field to flat file' do
|
|
81
|
-
field = flat_file.pad :autoname, width: 3
|
|
82
|
-
expect( field.padding? ).to be true
|
|
83
|
-
expect( field.name ).to eq( :pad_1 )
|
|
84
|
-
expect( flat_file.fields.size ).to eq( 1 )
|
|
85
|
-
expect( flat_file.width ).to eq( 3 )
|
|
86
|
-
expect( flat_file.pack_format ).to eq( 'A3' )
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
describe 'filter' do
|
|
91
|
-
before do
|
|
92
|
-
flat_file.reset_file_data
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it 'should not filter when none specified' do
|
|
96
|
-
field = flat_file.add_field :test
|
|
97
|
-
value = '123 '
|
|
98
|
-
filtered_value = field.filter value
|
|
99
|
-
expect( filtered_value ).to eq( '123 ' )
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'should filter for a specified block' do
|
|
103
|
-
field = flat_file.add_field :test, filter: ->(v) { v.strip }
|
|
104
|
-
value = '123 '
|
|
105
|
-
filtered_value = field.filter value
|
|
106
|
-
expect( filtered_value ).to eq( '123' )
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it 'should filter for a Filter Class' do
|
|
110
|
-
field = flat_file.add_field :test, filter: TestFilter
|
|
111
|
-
value = 'test'
|
|
112
|
-
filtered_value = field.filter value
|
|
113
|
-
expect( filtered_value ).to eq( 'TEST' )
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it 'should filter for an instance of a Filter Class' do
|
|
117
|
-
test_filter = TestFilter.new
|
|
118
|
-
field = flat_file.add_field :test, filter: test_filter
|
|
119
|
-
value = 'AbCd'
|
|
120
|
-
filtered_value = field.filter value
|
|
121
|
-
expect( filtered_value ).to eq( 'dCbA' )
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe FileData do
|
|
4
|
-
|
|
5
|
-
let(:flat_file) { Flat::File }
|
|
6
|
-
|
|
7
|
-
describe 'flat_file_data' do
|
|
8
|
-
it 'should be a Hash' do
|
|
9
|
-
expect( flat_file.flat_file_data ).to be_an_instance_of( Hash )
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'should have 4 keys' do
|
|
13
|
-
keys = flat_file.flat_file_data.keys
|
|
14
|
-
expect( keys.size ).to eq( 4 )
|
|
15
|
-
expect( keys ).to include( :width )
|
|
16
|
-
expect( keys ).to include( :pack_format )
|
|
17
|
-
expect( keys ).to include( :fields )
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe 'width' do
|
|
22
|
-
before do
|
|
23
|
-
flat_file.reset_file_data
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'has a convenience accessor' do
|
|
27
|
-
expect( flat_file.flat_file_data[:width] ).to eq( flat_file.width )
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'defaults to 0' do
|
|
31
|
-
expect( flat_file.width ).to eq( 0 )
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'can be changed' do
|
|
35
|
-
flat_file.width += 1
|
|
36
|
-
expect( flat_file.width ).to eq( 1 )
|
|
37
|
-
|
|
38
|
-
flat_file.width -= 2
|
|
39
|
-
expect( flat_file.width ).to eq( -1 )
|
|
40
|
-
|
|
41
|
-
flat_file.width = 12
|
|
42
|
-
expect( flat_file.width ).to eq( 12 )
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end
|
data/spec/lib/flat/file_spec.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Record do
|
|
4
|
-
|
|
5
|
-
let(:flat_file) { Flat::File }
|
|
6
|
-
|
|
7
|
-
describe Record::Definition do
|
|
8
|
-
before do
|
|
9
|
-
flat_file.reset_file_data
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'creates a new instance' do
|
|
13
|
-
record = Record::Definition.new flat_file, {}, 12
|
|
14
|
-
expect( record.line_number ).to eq( 12 )
|
|
15
|
-
expect( record.attributes ).to be_empty
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'has a getter per defined field' do
|
|
19
|
-
flat_file.add_field :field, width: 25
|
|
20
|
-
record = Record::Definition.new flat_file, {field: 'Field'}
|
|
21
|
-
expect( record.field ).to eq( 'Field' )
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'has a setter per defined field' do
|
|
25
|
-
flat_file.add_field :field, width: 25
|
|
26
|
-
record = Record::Definition.new flat_file, {field: 'Field'}
|
|
27
|
-
record.field = record.field.upcase
|
|
28
|
-
expect( record.field ).to eq( 'FIELD' )
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it 'throws an error for an unknown attribute' do
|
|
32
|
-
skip 'not capturing raised error correctly'
|
|
33
|
-
|
|
34
|
-
record = Record::Definition.new flat_file, {}, 12
|
|
35
|
-
expect( record.field ).to raise_error( Errors::FlatFileError )
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
end # => describe Record::Definition
|
|
39
|
-
|
|
40
|
-
end
|
data/spec/lib/flat_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'flat_file_helper'
|
|
3
|
-
|
|
4
|
-
describe Flat do
|
|
5
|
-
|
|
6
|
-
describe 'Version' do
|
|
7
|
-
it 'should verify current gem version' do
|
|
8
|
-
expect(Flat::VERSION).to eq('0.1.1')
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe 'Operations' do
|
|
13
|
-
let(:person_file) { PersonFile.new }
|
|
14
|
-
let(:data) { PersonFile::EXAMPLE_FILE }
|
|
15
|
-
let(:lines) { data.split("\n") }
|
|
16
|
-
let(:stream) { StringIO.new(data) }
|
|
17
|
-
|
|
18
|
-
it 'reads data from a flat file' do
|
|
19
|
-
count = 0
|
|
20
|
-
person_file.each_record( stream ) do |x, y|
|
|
21
|
-
count += 1
|
|
22
|
-
end
|
|
23
|
-
expect( count ).to eq( lines.size )
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end # => describe 'Operations'
|
|
27
|
-
|
|
28
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Setup the RSpec testing environment for Flat:
|
|
2
|
-
#
|
|
3
|
-
require 'coveralls'
|
|
4
|
-
Coveralls.wear!
|
|
5
|
-
|
|
6
|
-
require 'pry'
|
|
7
|
-
require 'flat'
|
|
8
|
-
|
|
9
|
-
class TestFilter
|
|
10
|
-
def self.filter(value)
|
|
11
|
-
value.upcase
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def filter(value)
|
|
15
|
-
value.reverse
|
|
16
|
-
end
|
|
17
|
-
end
|