csvrecord 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/Rakefile +4 -4
- data/lib/csvrecord.rb +2 -1
- data/lib/csvrecord/base.rb +9 -7
- data/lib/csvrecord/version.rb +8 -4
- data/test/test_record.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c829816b7962adf599248512674a08a58239e2
|
4
|
+
data.tar.gz: 1ff40ba6b3c3262f1ab0c0fc784352464fd076c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b11416fe2c82bd22fc0e6e4fd5fc5350154ae18ea565fb0c971796517f0c4cce88768b208496addc90a053cd42e8ae8d781c9db12c6f89b402174494710727
|
7
|
+
data.tar.gz: 6f90070d39333bdf39bf2639354d87ee76d6e4383566d2259c0a0983ac01e74443c864288d818a647c2c8b5cc23b76740ea0469c0185a17eb058ddf19be9e7c5
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# csvrecord - read in comma-separated values (csv) records with typed structs / schemas
|
2
2
|
|
3
3
|
|
4
|
-
* home :: [github.com/
|
5
|
-
* bugs :: [github.com/
|
4
|
+
* home :: [github.com/csvreader/csvrecord](https://github.com/csvreader/csvrecord)
|
5
|
+
* bugs :: [github.com/csvreader/csvrecord/issues](https://github.com/csvreader/csvrecord/issues)
|
6
6
|
* gem :: [rubygems.org/gems/csvrecord](https://rubygems.org/gems/csvrecord)
|
7
7
|
* rdoc :: [rubydoc.info/gems/csvrecord](http://rubydoc.info/gems/csvrecord)
|
8
8
|
* forum :: [wwwmake](http://groups.google.com/group/wwwmake)
|
@@ -164,7 +164,7 @@ And so on. That's it.
|
|
164
164
|
Good point. `CsvRecord` and `ActiveRecord` are different.
|
165
165
|
`ActiveRecord` has its own
|
166
166
|
database schema / attributes. Using [`CsvPack` - the tabular data
|
167
|
-
package](https://github.com/
|
167
|
+
package](https://github.com/csvreader/csvpack) you can, however, for your convenience auto-generate
|
168
168
|
`ActiveRecord` model classes
|
169
169
|
and `ActiveRecord` schema migrations (that is, tables and indices, etc.)
|
170
170
|
from the tabular
|
@@ -184,7 +184,7 @@ good old unix tradition - the work together but have its own (limited
|
|
184
184
|
|
185
185
|
## Alternatives
|
186
186
|
|
187
|
-
See the Libraries & Tools section in the [Awesome CSV](https://github.com/
|
187
|
+
See the Libraries & Tools section in the [Awesome CSV](https://github.com/csvspecs/awesome-csv#libraries--tools) page.
|
188
188
|
|
189
189
|
|
190
190
|
## License
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ Hoe.spec 'csvrecord' do
|
|
8
8
|
self.summary = "csvrecord - read in comma-separated values (csv) records with typed structs / schemas"
|
9
9
|
self.description = summary
|
10
10
|
|
11
|
-
self.urls = ['https://github.com/
|
11
|
+
self.urls = ['https://github.com/csvreader/csvrecord']
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
14
|
self.email = 'wwwmake@googlegroups.com'
|
@@ -18,14 +18,14 @@ Hoe.spec 'csvrecord' do
|
|
18
18
|
self.history_file = 'HISTORY.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
-
['record', '>=1.
|
22
|
-
['csvreader', '>=
|
21
|
+
['record', '>=1.2.0'],
|
22
|
+
['csvreader', '>=1.1.4']
|
23
23
|
]
|
24
24
|
|
25
25
|
self.licenses = ['Public Domain']
|
26
26
|
|
27
27
|
self.spec_extras = {
|
28
|
-
:
|
28
|
+
required_ruby_version: '>= 2.2.2'
|
29
29
|
}
|
30
30
|
|
31
31
|
end
|
data/lib/csvrecord.rb
CHANGED
data/lib/csvrecord/base.rb
CHANGED
@@ -8,13 +8,13 @@ module CsvRecord
|
|
8
8
|
|
9
9
|
class Base < Record::Base
|
10
10
|
|
11
|
-
def self.foreach( path, sep:
|
11
|
+
def self.foreach( path, sep: nil, headers: true )
|
12
12
|
|
13
13
|
## note: always use reader w/o headers to get row/record values as array of strings
|
14
14
|
## if headers: true -> skip first row
|
15
15
|
names = nil
|
16
16
|
|
17
|
-
CsvReader.foreach( path, sep: sep
|
17
|
+
CsvReader.foreach( path, sep: sep ) do |row|
|
18
18
|
if headers && names.nil?
|
19
19
|
names = row ## store header row / a.k.a. field/column names
|
20
20
|
else
|
@@ -27,12 +27,14 @@ def self.foreach( path, sep: Csv.config.sep, headers: true )
|
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
|
-
|
30
|
+
|
31
|
+
|
32
|
+
def self.parse( txt_or_rows, sep: nil, headers: true ) ## note: returns an (lazy) enumarator
|
31
33
|
if txt_or_rows.is_a? String
|
32
34
|
txt = txt_or_rows
|
33
35
|
## note: always use reader w/o headers to get row/record values as array of strings
|
34
36
|
## if headers: true -> skip first row
|
35
|
-
rows = CsvReader.parse( txt, sep: sep
|
37
|
+
rows = CsvReader.parse( txt, sep: sep )
|
36
38
|
else
|
37
39
|
### todo/fix: use only self.create( array-like ) for array-like data - why? why not?
|
38
40
|
rows = txt_or_rows
|
@@ -58,7 +60,7 @@ def self.parse( txt_or_rows, sep: Csv.config.sep, headers: true ) ## note: retu
|
|
58
60
|
end
|
59
61
|
|
60
62
|
|
61
|
-
def self.read( path, sep:
|
63
|
+
def self.read( path, sep: nil, headers: true ) ## not returns an enumarator
|
62
64
|
txt = File.open( path, 'r:utf-8' ).read
|
63
65
|
parse( txt, sep: sep, headers: headers )
|
64
66
|
end
|
@@ -94,14 +96,14 @@ def self.build_class( headers ) ## check: find a better name - why? why not?
|
|
94
96
|
clazz
|
95
97
|
end
|
96
98
|
|
97
|
-
def self.read( path, sep:
|
99
|
+
def self.read( path, sep: nil )
|
98
100
|
headers = CsvReader.header( path, sep: sep )
|
99
101
|
|
100
102
|
clazz = build_class( headers )
|
101
103
|
clazz.read( path, sep: sep )
|
102
104
|
end
|
103
105
|
|
104
|
-
def self.foreach( path, sep:
|
106
|
+
def self.foreach( path, sep: nil, &block )
|
105
107
|
headers = CsvReader.header( path, sep: sep )
|
106
108
|
|
107
109
|
clazz = build_class( headers )
|
data/lib/csvrecord/version.rb
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
|
4
4
|
module CsvRecord
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Version
|
7
|
+
MAJOR = 0
|
8
|
+
MINOR = 4
|
9
|
+
PATCH = 3
|
10
|
+
end
|
11
|
+
VERSION = [Version::MAJOR,
|
12
|
+
Version::MINOR,
|
13
|
+
Version::PATCH].join('.')
|
10
14
|
|
11
15
|
|
12
16
|
def self.version
|
data/test/test_record.rb
CHANGED
@@ -49,7 +49,7 @@ class TestRecord < MiniTest::Test
|
|
49
49
|
pp clazz2.fields
|
50
50
|
|
51
51
|
txt = File.open( "#{CsvRecord.test_data_dir}/beer.csv", 'r:utf-8' ).read
|
52
|
-
data =
|
52
|
+
data = CsvReader.parse( txt )
|
53
53
|
pp data
|
54
54
|
pp data.to_a ## note: includes header (first row with field names)
|
55
55
|
|
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.3
|
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-
|
11
|
+
date: 2018-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: record
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: csvreader
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.1.4
|
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: 1.1.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,7 +91,7 @@ files:
|
|
91
91
|
- test/test_record.rb
|
92
92
|
- test/test_record_auto.rb
|
93
93
|
- test/test_version.rb
|
94
|
-
homepage: https://github.com/
|
94
|
+
homepage: https://github.com/csvreader/csvrecord
|
95
95
|
licenses:
|
96
96
|
- Public Domain
|
97
97
|
metadata: {}
|