loady 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/loady/csv_loader.rb +12 -9
- data/lib/loady/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a1cc4ddea13a61ba00af056e95092eb9c6befe2
|
4
|
+
data.tar.gz: 78796d7745d5bf82e71eac66c830829f6247a3e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c5b0b8cc7c1e70939459624723780d60dd36510d9bab1e77028e63c065d2e3770bff5395ad843a5dd898e2dc756d6a930165730cde89e16e83cecdc8d17fb5e
|
7
|
+
data.tar.gz: 1fbd395af9f7cd47dce80860c4ec84002f55bf67254f130adafd83d4796f42e0fe2f821d94051133c047f9bd99c456d8d9601b5137ab7ce2842dfb17e70ae270
|
data/README.md
CHANGED
@@ -79,8 +79,17 @@ end
|
|
79
79
|
|
80
80
|
memory_logger.messages
|
81
81
|
=> [
|
82
|
-
'Line 123: Something bad happened.',
|
82
|
+
'Line 123: Something bad happened.',
|
83
83
|
'Line 456: Exception of some sort.',
|
84
84
|
'Finished. Loaded 9998 rows. 2 unprocessed rows.'
|
85
85
|
]
|
86
86
|
```
|
87
|
+
|
88
|
+
## Major Change in 1.0
|
89
|
+
|
90
|
+
Up to version 1.0, `loady` worked fundamentally differently than ruby's CSV
|
91
|
+
parser in that it did not support newlines. The benefit was that lines
|
92
|
+
with errant newlines could easily be ignored.
|
93
|
+
|
94
|
+
In version 1.0+, `loady` works like the stdlib ruby CSV parser, and you
|
95
|
+
must have properly formed CSV rows.
|
data/lib/loady/csv_loader.rb
CHANGED
@@ -16,16 +16,15 @@ module Loady
|
|
16
16
|
# see http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/classes/CSV.html#M000190
|
17
17
|
def read(filename, options = {}, &block)
|
18
18
|
@logger = options.delete(:logger) || default_logger
|
19
|
+
options[:headers] ||= options.delete(:skip_first_row)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
file.each do |line|
|
24
|
-
readline line, options, &block
|
25
|
-
end
|
21
|
+
CSV.foreach(filename, options) do |line|
|
22
|
+
readline line, options, &block
|
26
23
|
end
|
27
|
-
|
28
|
-
|
24
|
+
@logger.info "Finished. Loaded #{ @success } rows. #{ @warning } skipped rows."
|
25
|
+
rescue CSV::MalformedCSVError => ex
|
26
|
+
@logger.error ex.message
|
27
|
+
@logger.error "Stopped Loading after #{ @success } rows. #{ @warning } skipped rows."
|
29
28
|
end
|
30
29
|
|
31
30
|
class << self
|
@@ -38,7 +37,11 @@ module Loady
|
|
38
37
|
|
39
38
|
def readline(line, options)
|
40
39
|
@line_number += 1
|
41
|
-
row =
|
40
|
+
row = if line.respond_to?(:to_hash)
|
41
|
+
AttributeArray.new(line.to_hash.values)
|
42
|
+
else
|
43
|
+
AttributeArray.new(line)
|
44
|
+
end
|
42
45
|
|
43
46
|
if row.any?
|
44
47
|
yield row
|
data/lib/loady/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loady
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mocha
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.5.1
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: File loader with simple logging
|