hflr2 1.0.1 → 1.0.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.
- data/History.txt +4 -12
- data/README.txt +43 -45
- data/hflr2.gemspec +2 -2
- data/lib/hflr/fl_record_file.rb +10 -2
- data/test/flrfile_test.rb +17 -0
- metadata +4 -4
data/History.txt
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
== 1.0.
|
|
1
|
+
== 1.0.2 ==
|
|
2
2
|
|
|
3
|
-
*
|
|
4
|
-
* Added better exception handling for badly formatted output data
|
|
3
|
+
* Discriminator can be regular expression
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Removed useless files
|
|
10
|
-
* Corrected version number
|
|
11
|
-
|
|
12
|
-
== 1.0.1 / 2011-02-09
|
|
13
|
-
* Added ability to specify file format in Ruby with Range class (see example.rb in /test.)
|
|
14
|
-
|
|
5
|
+
== 1.0.1 ==
|
|
6
|
+
* Initial
|
data/README.txt
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
|
-
=
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
== Description:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Allows you to read and write files of fixed width records when the file contains one or more
|
|
10
|
-
than one type of record.
|
|
11
|
-
|
|
12
|
-
Install with 'gem install
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
45
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
= HFLR2
|
|
2
|
+
|
|
3
|
+
* https://rubygems.org/gems/hflr2/
|
|
4
|
+
|
|
5
|
+
== Description:
|
|
6
|
+
|
|
7
|
+
HFLR2 -- Hierarchical Fixed Length Records 2
|
|
8
|
+
|
|
9
|
+
Allows you to read and write files of fixed width records when the file contains one or more
|
|
10
|
+
than one type of record.
|
|
11
|
+
|
|
12
|
+
Install with 'gem install hflr2'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
See the tests and examples bundled with this gem.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
NOTE: This gem is based on the HFLR gem but may be not compatible with it.
|
|
19
|
+
|
|
20
|
+
== LICENSE:
|
|
21
|
+
|
|
22
|
+
(The MIT License)
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2012 Bozydar Sobczak
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
27
|
+
a copy of this software and associated documentation files (the
|
|
28
|
+
'Software'), to deal in the Software without restriction, including
|
|
29
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
30
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
31
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
32
|
+
the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be
|
|
35
|
+
included in all copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
38
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
39
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
40
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
41
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
42
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
43
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/hflr2.gemspec
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{hflr2}
|
|
5
|
-
s.version = "1.0.
|
|
5
|
+
s.version = "1.0.2"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Colin Davis", "Bozydar Sobczak"]
|
|
9
|
-
s.date = %q{2012-10-
|
|
9
|
+
s.date = %q{2012-10-29}
|
|
10
10
|
s.description = %q{HFLR2 -- Hierarchical Fixed Length Records
|
|
11
11
|
|
|
12
12
|
NOTE: This gem is a modification of the hflr gem. It can be not compatible with it.
|
data/lib/hflr/fl_record_file.rb
CHANGED
|
@@ -21,6 +21,7 @@ class FLRFile
|
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
def set_fast
|
|
25
26
|
@fast = !@record_type_labels.is_a?(Hash)
|
|
26
27
|
unless @fast
|
|
@@ -75,8 +76,15 @@ class FLRFile
|
|
|
75
76
|
if @record_type_labels.is_a?(Hash)
|
|
76
77
|
matching_pair = @record_type_labels.find do |_, value|
|
|
77
78
|
discriminator = value[:discriminator]
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
case discriminator
|
|
80
|
+
when String
|
|
81
|
+
position = value[:position] - 1
|
|
82
|
+
line[position..-1].start_with?(discriminator)
|
|
83
|
+
when Regexp
|
|
84
|
+
line =~ discriminator
|
|
85
|
+
else
|
|
86
|
+
nil
|
|
87
|
+
end
|
|
80
88
|
end
|
|
81
89
|
if matching_pair
|
|
82
90
|
matching_pair[0]
|
data/test/flrfile_test.rb
CHANGED
|
@@ -64,6 +64,23 @@ class FLRFileTest < Test::Unit::TestCase
|
|
|
64
64
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
def test_record_type_with_regexp
|
|
68
|
+
record_types = {:household => {:discriminator => /^H.*$/ }, :person => {:discriminator => /^P.*$/} }
|
|
69
|
+
|
|
70
|
+
sample_data_path = File.dirname(__FILE__)
|
|
71
|
+
fwf = FLRFile.new(
|
|
72
|
+
File.new("#{sample_data_path}/sample.dat"),
|
|
73
|
+
record_types, # Record types to read from the file, all others will be ignored
|
|
74
|
+
@layouts, # metadata for all record types
|
|
75
|
+
1, # column 0 starts at logical location 1
|
|
76
|
+
{:household => [:people], :person => [:household_id, :pserial]} # extra columns by record type
|
|
77
|
+
)
|
|
78
|
+
assert_nil fwf.get_record_type(nil)
|
|
79
|
+
assert_equal :household, fwf.get_record_type("H123")
|
|
80
|
+
assert_equal :person, fwf.get_record_type("P1234")
|
|
81
|
+
assert_equal nil, fwf.get_record_type("C123")
|
|
82
|
+
end
|
|
83
|
+
|
|
67
84
|
|
|
68
85
|
def test_build_record
|
|
69
86
|
sample_data_path = File.dirname(__FILE__)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hflr2
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 19
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 1.0.
|
|
9
|
+
- 2
|
|
10
|
+
version: 1.0.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Colin Davis
|
|
@@ -16,7 +16,7 @@ autorequire:
|
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
18
|
|
|
19
|
-
date: 2012-10-
|
|
19
|
+
date: 2012-10-29 00:00:00 Z
|
|
20
20
|
dependencies: []
|
|
21
21
|
|
|
22
22
|
description: |-
|