loady 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/README.md +6 -12
- data/lib/loady.rb +3 -5
- data/lib/loady/version.rb +1 -1
- data/loady.gemspec +2 -3
- data/test/test_attribute_array.rb +7 -7
- data/test/test_csv_loader.rb +8 -8
- data/test/test_helper.rb +1 -2
- data/test/test_memory_logger.rb +8 -8
- metadata +16 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf18fef23de1f5e6fdaf2105cd8fb869f1c34242
|
4
|
+
data.tar.gz: dc657ab3d90455b7e4aa7d590b65ca50e6587cc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4d2a56c7ce7798837c3eb97994b0d8d0d2ae876e266ba9cc5d98dabe8242a428d93bec1db1809589fb882e6535efbacb1f11374138c9581e8bc9d5a239f6201
|
7
|
+
data.tar.gz: 5bd7240dbfbcb811af20be78f60078b35bfe2e7930b3fe1fbb5656f044bf748832bf671b4c91fa050a9b203d7981d13a839ed08f7377638173aaeab78bb587b2
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.1.0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
Loady is a simple file reader and logger. Use it to quickly load any delimited file, continue on error rows, and do basic logging.
|
9
9
|
|
10
|
-
It works with MRI ruby 1.9
|
10
|
+
It works with MRI ruby 1.9.3+. It uses ruby's CSV library to parse rows.
|
11
11
|
|
12
12
|
## Install
|
13
13
|
|
@@ -31,8 +31,7 @@ By default, messages are logged to the standard output.
|
|
31
31
|
|
32
32
|
``` ruby
|
33
33
|
Loady.read "/your/file.csv" do |row|
|
34
|
-
#
|
35
|
-
puts "#{row[0]}, #{row[1]}, etc."
|
34
|
+
# handle each row
|
36
35
|
end
|
37
36
|
```
|
38
37
|
|
@@ -42,7 +41,7 @@ end
|
|
42
41
|
logger = Logger.new "/your/file.log"
|
43
42
|
|
44
43
|
Loady.read "/your/file.csv", logger: logger, skip_first_row: true do |row|
|
45
|
-
#
|
44
|
+
puts "#{row[0]}, #{row[1]}, etc."
|
46
45
|
end
|
47
46
|
```
|
48
47
|
|
@@ -51,6 +50,9 @@ end
|
|
51
50
|
``` ruby
|
52
51
|
Loady.read "/your/file.csv" do |row|
|
53
52
|
Monkey.create row.to_attributes [:name, :year, :mom]
|
53
|
+
|
54
|
+
# row.to_attributes [:name, :year, :mom]
|
55
|
+
# => { name: 'Bubbles', year: 2000, mom: 'Momma Bubbles' }
|
54
56
|
end
|
55
57
|
```
|
56
58
|
|
@@ -62,11 +64,3 @@ Loady.read "/your/file.tab", col_sep: "\t" do |row|
|
|
62
64
|
end
|
63
65
|
```
|
64
66
|
|
65
|
-
## Development
|
66
|
-
|
67
|
-
```
|
68
|
-
git clone git://github.com/teeparham/loady.git
|
69
|
-
cd loady
|
70
|
-
bundle
|
71
|
-
bundle exec rake
|
72
|
-
```
|
data/lib/loady.rb
CHANGED
@@ -6,10 +6,8 @@ module Loady
|
|
6
6
|
def read(*args, &block)
|
7
7
|
Loady::CsvLoader.new.read(*args, &block)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
alias csv read
|
10
11
|
|
11
|
-
|
12
|
-
Loady::CsvLoader.new.read(*args, &block)
|
13
|
-
end
|
14
|
-
module_function :csv
|
12
|
+
module_function :read, :csv
|
15
13
|
end
|
data/lib/loady/version.rb
CHANGED
data/loady.gemspec
CHANGED
@@ -17,10 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = []
|
18
18
|
s.require_paths = %w(lib)
|
19
19
|
|
20
|
-
s.required_ruby_version = '>=1.9.
|
20
|
+
s.required_ruby_version = '>= 1.9.3'
|
21
21
|
|
22
22
|
s.add_development_dependency "mocha"
|
23
23
|
s.add_development_dependency "rake"
|
24
|
-
s.add_development_dependency "
|
25
|
-
s.add_development_dependency "test-unit"
|
24
|
+
s.add_development_dependency "minitest"
|
26
25
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class AttributeArrayTest <
|
4
|
-
|
3
|
+
class AttributeArrayTest < MiniTest::Spec
|
4
|
+
it "respond to to_attributes" do
|
5
5
|
aa = Loady::AttributeArray.new
|
6
6
|
assert aa.respond_to? :to_attributes
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "initialize with Array" do
|
10
10
|
aa = Loady::AttributeArray.new([1,2])
|
11
11
|
assert_equal [1,2], aa
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
describe "#to_attributes" do
|
15
|
+
it "return named attributes" do
|
16
16
|
row = Loady::AttributeArray.new(['Bubbles ', '2000', ' King Kong '])
|
17
17
|
attrs = row.to_attributes [:name, :year, :mom]
|
18
18
|
assert_equal attrs.size, 3
|
@@ -21,7 +21,7 @@ class AttributeArrayTest < Test::Unit::TestCase
|
|
21
21
|
assert_equal attrs[:mom], 'King Kong'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
it "return named attributes when missing values" do
|
25
25
|
row = Loady::AttributeArray.new(['Bubbles ', '2000'])
|
26
26
|
attrs = row.to_attributes [:name, :year, :mom]
|
27
27
|
assert_equal attrs.size, 3
|
@@ -30,4 +30,4 @@ class AttributeArrayTest < Test::Unit::TestCase
|
|
30
30
|
assert_nil attrs[:mom]
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/test/test_csv_loader.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class CsvLoaderTest <
|
4
|
-
|
3
|
+
class CsvLoaderTest < MiniTest::Spec
|
4
|
+
it "delegate Loady.csv to instance #read" do
|
5
5
|
Loady::CsvLoader.any_instance.expects :read
|
6
6
|
Loady.csv("file")
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "delegate Loady.read to instance #read" do
|
10
10
|
Loady::CsvLoader.any_instance.expects :read
|
11
11
|
Loady.read("file")
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
it "delegate #read to instance #read" do
|
15
15
|
Loady::CsvLoader.any_instance.expects :read
|
16
16
|
Loady::CsvLoader.read("file")
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
it "read file1" do
|
20
20
|
monkeys = []
|
21
21
|
|
22
22
|
Loady.read "test/csv/file1.csv", skip_first_row: true do |row|
|
@@ -30,7 +30,7 @@ class CsvLoaderTest < Test::Unit::TestCase
|
|
30
30
|
assert_equal monkeys[9][:year], "1933", "last row year"
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
it "read file2 with logger using named attributes" do
|
34
34
|
logger = Logger.new("/dev/null")
|
35
35
|
monkeys = []
|
36
36
|
|
@@ -45,7 +45,7 @@ class CsvLoaderTest < Test::Unit::TestCase
|
|
45
45
|
assert_equal monkeys[9][:year], "1933", "last row year"
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
it "read file3, a tab-delimited file" do
|
49
49
|
monkeys = []
|
50
50
|
|
51
51
|
Loady.read "test/csv/file3.dat", skip_first_row: true, col_sep: "\t" do |row|
|
@@ -59,4 +59,4 @@ class CsvLoaderTest < Test::Unit::TestCase
|
|
59
59
|
assert_equal monkeys[9][:year], "1933", "last row year"
|
60
60
|
end
|
61
61
|
|
62
|
-
end
|
62
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/test_memory_logger.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class MemoryLoggerTest <
|
4
|
-
|
5
|
-
|
3
|
+
class MemoryLoggerTest < MiniTest::Spec
|
4
|
+
describe "memory logger" do
|
5
|
+
before do
|
6
6
|
@logger = Loady::MemoryLogger.new
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
it "have no messages" do
|
10
10
|
assert_empty @logger.messages
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
it "log warning" do
|
14
14
|
@logger.warn "message"
|
15
15
|
assert_equal "message", @logger.messages.first
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "log info" do
|
19
19
|
@logger.info "message"
|
20
20
|
assert_equal "message", @logger.messages.first
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
it "log error" do
|
24
24
|
@logger.error "message"
|
25
25
|
assert_equal "message", @logger.messages.first
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loady
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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: 2014-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mocha
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: test-unit
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
55
|
description: CSV file loader with simple logging
|
@@ -73,9 +59,9 @@ executables: []
|
|
73
59
|
extensions: []
|
74
60
|
extra_rdoc_files: []
|
75
61
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .ruby-version
|
78
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".travis.yml"
|
79
65
|
- Gemfile
|
80
66
|
- README.md
|
81
67
|
- Rakefile
|
@@ -102,17 +88,17 @@ require_paths:
|
|
102
88
|
- lib
|
103
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
90
|
requirements:
|
105
|
-
- -
|
91
|
+
- - ">="
|
106
92
|
- !ruby/object:Gem::Version
|
107
|
-
version: 1.9.
|
93
|
+
version: 1.9.3
|
108
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
95
|
requirements:
|
110
|
-
- -
|
96
|
+
- - ">="
|
111
97
|
- !ruby/object:Gem::Version
|
112
98
|
version: '0'
|
113
99
|
requirements: []
|
114
100
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.1
|
101
|
+
rubygems_version: 2.2.1
|
116
102
|
signing_key:
|
117
103
|
specification_version: 4
|
118
104
|
summary: CSV file loader with simple logging
|