csvrecord 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/csvrecord/base.rb +30 -13
- data/lib/csvrecord/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea06a8e7e4761cb22c4e19c20680c86127cb80d2
|
4
|
+
data.tar.gz: c1c5183693a2e29405ef95e027354a012bbcdaa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a102eaf53b9861306dc8807d5c9b4c04077b9a50c03110a76963304a693dd3d722bb1442d13960bb966f423dedfa2f81e0f5749870b3343d30c1718266f0155f
|
7
|
+
data.tar.gz: b999b4408515fe0068eb032b8c0f0677df8166bc5523698edbcdf319aeddd22a71ea3d47e3f51adce94b1717b5ce6938390b626469b5412a0ca4577dbed003f0
|
data/Rakefile
CHANGED
data/lib/csvrecord/base.rb
CHANGED
@@ -9,12 +9,20 @@ module CsvRecord
|
|
9
9
|
class Base < Record::Base
|
10
10
|
|
11
11
|
def self.foreach( path, sep: Csv.config.sep, headers: true )
|
12
|
-
CsvReader.foreach( path, sep: sep, headers: headers ) do |row|
|
13
|
-
rec = new
|
14
|
-
values = CsvReader.unwrap( row )
|
15
|
-
rec.parse( values )
|
16
12
|
|
17
|
-
|
13
|
+
## note: always use reader w/o headers to get row/record values as array of strings
|
14
|
+
## if headers: true -> skip first row
|
15
|
+
names = nil
|
16
|
+
|
17
|
+
CsvReader.foreach( path, sep: sep, headers: false ) do |row|
|
18
|
+
if headers && names.nil?
|
19
|
+
names = row ## store header row / a.k.a. field/column names
|
20
|
+
else
|
21
|
+
rec = new
|
22
|
+
rec.parse( row )
|
23
|
+
|
24
|
+
yield( rec ) ## check: use block.class( rec ) - why? why not?
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -22,21 +30,29 @@ end
|
|
22
30
|
def self.parse( txt_or_rows, sep: Csv.config.sep, headers: true ) ## note: returns an (lazy) enumarator
|
23
31
|
if txt_or_rows.is_a? String
|
24
32
|
txt = txt_or_rows
|
25
|
-
|
33
|
+
## note: always use reader w/o headers to get row/record values as array of strings
|
34
|
+
## if headers: true -> skip first row
|
35
|
+
rows = CsvReader.parse( txt, sep: sep, headers: false )
|
26
36
|
else
|
27
37
|
### todo/fix: use only self.create( array-like ) for array-like data - why? why not?
|
28
|
-
rows = txt_or_rows
|
38
|
+
rows = txt_or_rows
|
29
39
|
end
|
30
40
|
|
31
|
-
pp rows
|
41
|
+
## pp rows
|
42
|
+
|
43
|
+
|
44
|
+
names = nil
|
32
45
|
|
33
46
|
Enumerator.new do |yielder|
|
34
47
|
rows.each do |row|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
48
|
+
if headers && names.nil?
|
49
|
+
names = row ## store header row / a.k.a. field/column names
|
50
|
+
else
|
51
|
+
rec = new
|
52
|
+
rec.parse( row )
|
53
|
+
|
54
|
+
yielder.yield( rec )
|
55
|
+
end
|
40
56
|
end
|
41
57
|
end
|
42
58
|
end
|
@@ -59,6 +75,7 @@ end # class Base
|
|
59
75
|
|
60
76
|
|
61
77
|
|
78
|
+
|
62
79
|
###########################################
|
63
80
|
## "magic" lazy auto-build schema from headers versions
|
64
81
|
|
data/lib/csvrecord/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvrecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: record
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|