loady 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/loady.rb +1 -1
- data/lib/loady/{array.rb → attribute_array.rb} +3 -2
- data/lib/loady/csv_loader.rb +3 -4
- data/lib/loady/version.rb +1 -1
- data/loady.gemspec +2 -2
- data/test/{test_loady.rb → test_attribute_array.rb} +13 -9
- metadata +5 -11
data/lib/loady.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Loady
|
2
|
-
|
2
|
+
class AttributeArray < Array
|
3
3
|
|
4
4
|
# usage:
|
5
|
-
# ['john', 'doe']
|
5
|
+
# aa = Loady::AttributeArray.new(['john', 'doe'])
|
6
|
+
# aa.to_attributes([:first, :last])
|
6
7
|
# => { first: 'john', last: 'doe' }
|
7
8
|
#
|
8
9
|
# options:
|
data/lib/loady/csv_loader.rb
CHANGED
@@ -6,8 +6,8 @@ module Loady
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
# valid options:
|
9
|
-
# :
|
10
|
-
# :
|
9
|
+
# skip_first_row: true -- default = false
|
10
|
+
# logger: Logger.new('/somewhere/file.log') -- default = Logger.new(STDOUT)
|
11
11
|
# plus any valid options you can pass to CSV.new:
|
12
12
|
# see http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/classes/CSV.html#M000190
|
13
13
|
def read(filename, options={})
|
@@ -26,8 +26,7 @@ module Loady
|
|
26
26
|
begin
|
27
27
|
line_number += 1
|
28
28
|
|
29
|
-
row = CSV.parse(line, options)[0]
|
30
|
-
row.extend Loady::Array
|
29
|
+
row = Loady::AttributeArray.new CSV.parse(line, options)[0]
|
31
30
|
|
32
31
|
unless row.empty?
|
33
32
|
yield row
|
data/lib/loady/version.rb
CHANGED
data/loady.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Loady::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Tee Parham"]
|
10
|
-
s.email =
|
10
|
+
s.email = %w(tee@neighborland.com)
|
11
11
|
s.homepage = "http://github.com/teeparham/loady"
|
12
12
|
s.summary = %q{CSV file loader with simple logging}
|
13
13
|
s.description = %q{CSV file loader with simple logging}
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths =
|
20
|
+
s.require_paths = %w(lib)
|
21
21
|
|
22
22
|
s.add_development_dependency "test-unit"
|
23
23
|
s.add_development_dependency "shoulda"
|
@@ -1,13 +1,20 @@
|
|
1
1
|
require File.expand_path('test_helper.rb', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class
|
4
|
-
|
3
|
+
class AttributeArrayTest < Test::Unit::TestCase
|
4
|
+
should "respond to to_attributes" do
|
5
|
+
aa = Loady::AttributeArray.new
|
6
|
+
assert aa.respond_to? :to_attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
should "initialize with Array" do
|
10
|
+
aa = Loady::AttributeArray.new([1,2])
|
11
|
+
assert_equal [1,2], aa
|
12
|
+
end
|
5
13
|
|
14
|
+
context "#to_attributes" do
|
6
15
|
should "return named attributes" do
|
7
|
-
row = ['Bubbles ', '2000', ' King Kong ']
|
8
|
-
row.extend Loady::Array
|
16
|
+
row = Loady::AttributeArray.new(['Bubbles ', '2000', ' King Kong '])
|
9
17
|
attrs = row.to_attributes [:name, :year, :mom]
|
10
|
-
|
11
18
|
assert_equal attrs.size, 3
|
12
19
|
assert_equal attrs[:name], 'Bubbles'
|
13
20
|
assert_equal attrs[:year], '2000'
|
@@ -15,15 +22,12 @@ class LoadyTest < Test::Unit::TestCase
|
|
15
22
|
end
|
16
23
|
|
17
24
|
should "return named attributes when missing values" do
|
18
|
-
row = ['Bubbles ', '2000']
|
19
|
-
row.extend Loady::Array
|
25
|
+
row = Loady::AttributeArray.new(['Bubbles ', '2000'])
|
20
26
|
attrs = row.to_attributes [:name, :year, :mom]
|
21
|
-
|
22
27
|
assert_equal attrs.size, 3
|
23
28
|
assert_equal attrs[:name], 'Bubbles'
|
24
29
|
assert_equal attrs[:year], '2000'
|
25
30
|
assert_nil attrs[:mom]
|
26
31
|
end
|
27
|
-
|
28
32
|
end
|
29
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loady
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- README.rdoc
|
73
73
|
- Rakefile
|
74
74
|
- lib/loady.rb
|
75
|
-
- lib/loady/
|
75
|
+
- lib/loady/attribute_array.rb
|
76
76
|
- lib/loady/csv_loader.rb
|
77
77
|
- lib/loady/memory_logger.rb
|
78
78
|
- lib/loady/version.rb
|
@@ -80,9 +80,9 @@ files:
|
|
80
80
|
- test/csv/file1.csv
|
81
81
|
- test/csv/file2.csv
|
82
82
|
- test/csv/file3.dat
|
83
|
+
- test/test_attribute_array.rb
|
83
84
|
- test/test_csv_loader.rb
|
84
85
|
- test/test_helper.rb
|
85
|
-
- test/test_loady.rb
|
86
86
|
- test/test_memory_logger.rb
|
87
87
|
homepage: http://github.com/teeparham/loady
|
88
88
|
licenses: []
|
@@ -96,18 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
hash: -1716122112452948356
|
102
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
100
|
none: false
|
104
101
|
requirements:
|
105
102
|
- - ! '>='
|
106
103
|
- !ruby/object:Gem::Version
|
107
104
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: -1716122112452948356
|
111
105
|
requirements: []
|
112
106
|
rubyforge_project: loady
|
113
107
|
rubygems_version: 1.8.24
|
@@ -118,7 +112,7 @@ test_files:
|
|
118
112
|
- test/csv/file1.csv
|
119
113
|
- test/csv/file2.csv
|
120
114
|
- test/csv/file3.dat
|
115
|
+
- test/test_attribute_array.rb
|
121
116
|
- test/test_csv_loader.rb
|
122
117
|
- test/test_helper.rb
|
123
|
-
- test/test_loady.rb
|
124
118
|
- test/test_memory_logger.rb
|