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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f9b5900a09323251bb9cf7fef7211c5692a5ac3
4
- data.tar.gz: db705e1ba91bcd30ac538947d1518521a92ce76a
3
+ metadata.gz: ea06a8e7e4761cb22c4e19c20680c86127cb80d2
4
+ data.tar.gz: c1c5183693a2e29405ef95e027354a012bbcdaa9
5
5
  SHA512:
6
- metadata.gz: 34c7f0d23df73725a8f6616024cda30ab89938e94e1032727b8caee434263dc2551547c8f6599c6294f6fa9fe0d1a9255ccd957a2ef6dda277c6e7f044506bc2
7
- data.tar.gz: 49a205a98277d5e7842f06a052c5306cb3ce475de9fe3fa056fef411f923a96bf2f254b70b07f70db771f09832630bd95b40b9675992bcb4c8b7a8a750ed7ba1
6
+ metadata.gz: a102eaf53b9861306dc8807d5c9b4c04077b9a50c03110a76963304a693dd3d722bb1442d13960bb966f423dedfa2f81e0f5749870b3343d30c1718266f0155f
7
+ data.tar.gz: b999b4408515fe0068eb032b8c0f0677df8166bc5523698edbcdf319aeddd22a71ea3d47e3f51adce94b1717b5ce6938390b626469b5412a0ca4577dbed003f0
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Hoe.spec 'csvrecord' do
19
19
 
20
20
  self.extra_deps = [
21
21
  ['record', '>=1.1.1'],
22
- ['csvreader']
22
+ ['csvreader', '>=0.3.0']
23
23
  ]
24
24
 
25
25
  self.licenses = ['Public Domain']
@@ -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
- yield( rec ) ## check: use block.class( rec ) - why? why not?
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
- rows = CsvReader.parse( txt, sep: sep, headers: headers )
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 ## assume array-like records that responds to :each
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
- rec = new
36
- values = CsvReader.unwrap( row )
37
- rec.parse( values )
38
-
39
- yielder.yield( rec )
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
 
@@ -5,7 +5,7 @@ module CsvRecord
5
5
 
6
6
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
7
7
  MINOR = 4
8
- PATCH = 1
8
+ PATCH = 2
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
 
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.1
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-15 00:00:00.000000000 Z
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: '0'
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: '0'
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement