rseed 1.0.15 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/rseed/csv_adapter.rb +36 -16
- data/lib/rseed/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Zjg1NmMzYWRkZWYxMzgzMTNkNjE2NWU3ZDk0ZGRlNWFjMDg1YmY5OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjAyZWQ4ODkzYzBjMmQzMWQ4Njk2MDZhNzUwMWEzN2ZlMjUwMTYyNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTdkYTk3ZmU2NTI5MmRlNzY5MTZiYmI2OGQyZDlkMDBhNzEzMjg3NGQwMWFh
|
10
|
+
MGIyMzlhMjdjZDljYTc4MTFjMDc5NjAyNGM0M2RlMGU0Yjc4NDBjNGVhNDZj
|
11
|
+
YTIyZDFhMTQ5N2E3Yzg3YzhlODg4YmFmZThhZDRkODc2MzExNmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjVlNjQ0MjRhMjJjOTM3NGU4NzAzYjU3MDM2YTg2MjUxYTA1MzhmNWJhZmJm
|
14
|
+
OWJhZmU5YmYzNzZlMTFhNjkwNmIzNmMzNmFhZmY1ZTYyYjQzM2Q3NzI0Njcy
|
15
|
+
YWY2ZTBmNzI1ODZiM2MyMzFmNmNkNTNjOWU5OGM2NzQwY2U5YWI=
|
data/lib/rseed/csv_adapter.rb
CHANGED
@@ -7,36 +7,56 @@ module Rseed
|
|
7
7
|
def preprocess
|
8
8
|
return false unless file
|
9
9
|
logger.info "Preprocessing CSV file: #{file.to_s.yellow}"
|
10
|
-
@estimated_rows = CSV.read(file).length
|
10
|
+
@estimated_rows = CSV.read(file).length
|
11
|
+
@estimated_rows -=1 unless options[:headers]
|
11
12
|
logger.info "Estimated Rows: #{@estimated_rows}".magenta
|
12
13
|
true
|
13
14
|
end
|
14
15
|
|
16
|
+
def match_headers input
|
17
|
+
headers = {}
|
18
|
+
|
19
|
+
input.each_with_index do |column_value, index|
|
20
|
+
column = index + 1
|
21
|
+
converter_attributes.each do |attribute|
|
22
|
+
if attribute.matches? column_value.strip
|
23
|
+
logger.debug "Found header for #{attribute.name} at column #{column}".green
|
24
|
+
if (headers[attribute.name].nil?)
|
25
|
+
headers[attribute.name] = column
|
26
|
+
else
|
27
|
+
logger.error "Found duplicate header '#{attribute.name}' on columns #{column} and #{headers[attribute.name]}.".red
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
return headers
|
34
|
+
end
|
35
|
+
|
15
36
|
def process &block
|
37
|
+
self.options = self.options.to_hash.symbolize_keys
|
38
|
+
|
16
39
|
headers = {}
|
17
40
|
header = true
|
41
|
+
|
42
|
+
if options[:headers]
|
43
|
+
headers = match_headers(options[:headers].split(','))
|
44
|
+
header = false
|
45
|
+
unless all_headers_found(headers)
|
46
|
+
logger.error "The supplied headers did not match all attributes".red
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
18
51
|
data_count = 0
|
19
52
|
row_number = 0
|
20
53
|
|
21
54
|
# Get an estimate of the number of rows in the file
|
22
|
-
csv_options = {:encoding => 'windows-1251:utf-8'}.merge(self.options
|
55
|
+
csv_options = {:encoding => 'windows-1251:utf-8'}.merge(self.options)
|
23
56
|
CSV.foreach(file, csv_options) do |row|
|
24
57
|
row_number += 1
|
25
58
|
if (header)
|
26
|
-
|
27
|
-
row.each do |column_value|
|
28
|
-
column += 1
|
29
|
-
converter_attributes.each do |attribute|
|
30
|
-
if attribute.matches? column_value
|
31
|
-
logger.debug "Found header for #{attribute.name} at column #{column}".green
|
32
|
-
if (headers[attribute.name].nil?)
|
33
|
-
headers[attribute.name] = column
|
34
|
-
else
|
35
|
-
logger.error "Found duplicate header '#{attribute.name}' on columns #{column} and #{headers[attribute.name]}.".red
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
59
|
+
headers = match_headers(row)
|
40
60
|
unless all_headers_found(headers)
|
41
61
|
logger.error "Missing headers".red
|
42
62
|
break
|
data/lib/rseed/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rseed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Monagle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|