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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9542f9292a6cf6f2d12a033170e70a181235d49f
4
- data.tar.gz: 4615571fbee275ea5cf7527236d97e440c4fda53
3
+ metadata.gz: 6a1cc4ddea13a61ba00af056e95092eb9c6befe2
4
+ data.tar.gz: 78796d7745d5bf82e71eac66c830829f6247a3e1
5
5
  SHA512:
6
- metadata.gz: c0d25286af535b360d361355ce5fc1dce248a760fd4c06d2515d6acf9df1165540ea7ee8656658daae7402032e58c73fe2ade6c92664f5c7f20338b19ddd2023
7
- data.tar.gz: 19c248583518f999a7eafe890d5ae36c1a23bf69948b65584461e2724190738e3d0af815576971afe93e30d1998e957ae141f77a328f8ccdcdf12819f56d1cb3
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.
@@ -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
- File.open(filename, "r") do |file|
21
- file.gets if options.delete(:skip_first_row)
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
- @logger.info "Finished. Loaded #{ @success } rows. #{ @warning } unprocessed rows."
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 = AttributeArray.new(CSV.parse(line, options)[0])
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
@@ -1,3 +1,3 @@
1
1
  module Loady
2
- VERSION = "0.9.0"
2
+ VERSION = "1.0.0"
3
3
  end
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.9.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: 2015-01-20 00:00:00.000000000 Z
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.4.5
89
+ rubygems_version: 2.5.1
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: File loader with simple logging