sheet_mapper 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -1
- data/lib/sheet_mapper/collection.rb +7 -7
- data/lib/sheet_mapper/version.rb +1 -1
- data/test/base_test.rb +15 -2
- data/test/collection_test.rb +8 -10
- metadata +4 -4
data/README.md
CHANGED
@@ -92,7 +92,10 @@ collection.cell(1, 2) => "foo"
|
|
92
92
|
|
93
93
|
## Contributors
|
94
94
|
|
95
|
-
SheetMapper was created by [Nathan Esquenazi](http://github.com/nesquena) at Miso in 2012.
|
95
|
+
SheetMapper was created by [Nathan Esquenazi](http://github.com/nesquena) at Miso in 2012. The following users
|
96
|
+
contributed to the project:
|
97
|
+
|
98
|
+
* (Derek Lindahl)[https://github.com/dlindahl] - Added simple delegation to collections
|
96
99
|
|
97
100
|
## Tasks
|
98
101
|
|
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
module SheetMapper
|
2
4
|
class CollectionNotFound < StandardError; end
|
3
5
|
|
4
|
-
class Collection
|
6
|
+
class Collection < SimpleDelegator
|
5
7
|
attr_reader :records, :worksheet
|
6
8
|
|
7
9
|
# spreadsheet is a SheetMapper::Spreadsheet
|
@@ -13,12 +15,6 @@ module SheetMapper
|
|
13
15
|
@records = process_records!
|
14
16
|
end
|
15
17
|
|
16
|
-
# Each block for every mapped record
|
17
|
-
# @collection.each { |m| ...mapped obj... }
|
18
|
-
def each(&block)
|
19
|
-
records.each(&block)
|
20
|
-
end
|
21
|
-
|
22
18
|
# Returns an array of mapped records
|
23
19
|
# @collection.rows => [<SheetMapper::Base>, ...]
|
24
20
|
def rows
|
@@ -45,6 +41,10 @@ module SheetMapper
|
|
45
41
|
@records = process_records!
|
46
42
|
end
|
47
43
|
|
44
|
+
def __getobj__
|
45
|
+
@records
|
46
|
+
end
|
47
|
+
|
48
48
|
protected
|
49
49
|
|
50
50
|
# Converts all valid raw data hashes into mapped records
|
data/lib/sheet_mapper/version.rb
CHANGED
data/test/base_test.rb
CHANGED
@@ -43,7 +43,7 @@ describe "Base" do
|
|
43
43
|
assert_equal 42, @test.age
|
44
44
|
assert_equal "Red", @test.color
|
45
45
|
end
|
46
|
-
end #
|
46
|
+
end # attribute methods
|
47
47
|
|
48
48
|
context "for assignment of attributes" do
|
49
49
|
setup do
|
@@ -56,7 +56,20 @@ describe "Base" do
|
|
56
56
|
assert_equal 23, @test[:age]
|
57
57
|
assert_equal "Black", @test[:color]
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end # assignment of attributes
|
60
|
+
|
61
|
+
context "for attributes method" do
|
62
|
+
setup do
|
63
|
+
@test = TestBase.new(1, @data)
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return attributes hash" do
|
67
|
+
hash = @test.attributes
|
68
|
+
assert_equal "BOB", hash[:name]
|
69
|
+
assert_equal 42, hash[:age]
|
70
|
+
assert_equal "Red", hash[:color]
|
71
|
+
end
|
72
|
+
end # attributes method
|
60
73
|
|
61
74
|
context "for accessing attribute" do
|
62
75
|
setup do
|
data/test/collection_test.rb
CHANGED
@@ -33,20 +33,18 @@ describe "Collection" do
|
|
33
33
|
end
|
34
34
|
end # worksheet
|
35
35
|
|
36
|
-
context "
|
37
|
-
|
36
|
+
context "Enumerability" do
|
37
|
+
subject do
|
38
38
|
@collection = SheetMapper::Collection.new(@spreadsheet, @worksheet)
|
39
39
|
end
|
40
40
|
|
41
|
-
should "
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
assert_equal ["Susan", 34], rows[1].tuple
|
47
|
-
assert_equal ["Joey", 67], rows[2].tuple
|
41
|
+
should "behave like an Enumerable" do
|
42
|
+
assert_equal subject.first, subject.records.first
|
43
|
+
assert subject.respond_to?(:each)
|
44
|
+
assert subject.respond_to?(:find)
|
45
|
+
assert subject.respond_to?(:map)
|
48
46
|
end
|
49
|
-
end #
|
47
|
+
end # enum
|
50
48
|
|
51
49
|
context "for rows method" do
|
52
50
|
setup do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheet_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Esquenazi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: google-spreadsheet-ruby
|