csv_madness 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.markdown +21 -3
- data/Gemfile +10 -7
- data/README.rdoc +96 -63
- data/Rakefile +7 -15
- data/VERSION +1 -1
- data/lib/csv_madness.rb +4 -13
- data/lib/csv_madness/builder.rb +97 -0
- data/lib/csv_madness/gem_api.rb +12 -0
- data/lib/csv_madness/record.rb +38 -1
- data/lib/csv_madness/sheet.rb +196 -33
- data/test/csv/forbidden_column.csv +2 -0
- data/test/csv/splitter.csv +11 -0
- data/test/csv/test_column_types.csv +3 -0
- data/test/csv/with_nils.csv +5 -0
- data/test/helper.rb +26 -19
- data/test/test_builder.rb +33 -0
- data/test/test_csv_madness.rb +2 -3
- data/test/test_merging_columns.rb +40 -0
- data/test/test_reloading_spreadsheet.rb +30 -0
- data/test/test_sheet.rb +102 -3
- metadata +26 -85
data/test/test_csv_madness.rb
CHANGED
@@ -3,7 +3,6 @@ require 'helper'
|
|
3
3
|
class TestCsvMadness < MadTestCase
|
4
4
|
context "all:" do
|
5
5
|
setup do
|
6
|
-
set_spreadsheet_paths
|
7
6
|
load_simple_spreadsheet
|
8
7
|
end
|
9
8
|
|
@@ -14,12 +13,12 @@ class TestCsvMadness < MadTestCase
|
|
14
13
|
context "testing sheet basics" do
|
15
14
|
should "not accept duplicate search paths" do
|
16
15
|
@path_count = CsvMadness::Sheet.search_paths.length
|
17
|
-
CsvMadness::Sheet.add_search_path(
|
16
|
+
CsvMadness::Sheet.add_search_path( @csv_load_path )
|
18
17
|
assert_equal @path_count, CsvMadness::Sheet.search_paths.length
|
19
18
|
end
|
20
19
|
|
21
20
|
should "load a simple spreadsheet" do
|
22
|
-
simple = CsvMadness::Sheet.from("simple.csv")
|
21
|
+
simple = CsvMadness::Sheet.from( "simple.csv" )
|
23
22
|
assert_equal "Mary", simple[0].fname
|
24
23
|
assert_equal "Paxton", simple[1].lname
|
25
24
|
assert_equal "72", simple[2].age
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMergingColumns < MadTestCase
|
4
|
+
context "with a simple spreadsheet loaded" do
|
5
|
+
setup do
|
6
|
+
set_spreadsheet_paths
|
7
|
+
load_simple_spreadsheet
|
8
|
+
end
|
9
|
+
|
10
|
+
teardown do
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
should "merge :age column into :born column, and drop :born column" do
|
15
|
+
@simple.merge_columns( :age, :born )
|
16
|
+
assert @simple.columns.include?( :born )
|
17
|
+
assert !@simple.columns.include?( :age )
|
18
|
+
|
19
|
+
load_mary
|
20
|
+
assert_equal "27", @mary.born
|
21
|
+
end
|
22
|
+
|
23
|
+
should "merge :age column into :born column, and keep :born column" do
|
24
|
+
@simple.merge_columns( :age, :born, :drop_source => false )
|
25
|
+
assert @simple.columns.include?( :born )
|
26
|
+
assert @simple.columns.include?( :age )
|
27
|
+
|
28
|
+
load_mary
|
29
|
+
assert_equal "27", @mary.born
|
30
|
+
end
|
31
|
+
|
32
|
+
should "concatanate first and last names" do
|
33
|
+
@simple.concatenate( :fname, :lname, :separator => " " )
|
34
|
+
@simple.rename_column( :fname, :full_name )
|
35
|
+
|
36
|
+
load_darwin
|
37
|
+
assert_equal "Charles Darwin", @darwin.full_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCsvMadness < MadTestCase
|
4
|
+
context "with a simple spreadsheet loaded" do
|
5
|
+
setup do
|
6
|
+
set_spreadsheet_paths
|
7
|
+
load_simple_spreadsheet
|
8
|
+
set_person_records
|
9
|
+
end
|
10
|
+
|
11
|
+
should "reset spreadsheet by reloading from file" do
|
12
|
+
assert @mary.respond_to?(:lname)
|
13
|
+
assert @darwin.respond_to?(:fname)
|
14
|
+
assert @mary.born.is_a?(String)
|
15
|
+
|
16
|
+
muck_up_spreadsheet
|
17
|
+
set_person_records
|
18
|
+
|
19
|
+
assert !@mary.respond_to?(:lname)
|
20
|
+
assert !@darwin.respond_to?(:fname)
|
21
|
+
assert @mary.born.is_a?(Float)
|
22
|
+
|
23
|
+
@simple.reload_spreadsheet
|
24
|
+
set_person_records
|
25
|
+
|
26
|
+
assert @mary.respond_to?(:lname)
|
27
|
+
assert @darwin.respond_to?(:fname)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/test_sheet.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestSheet < MadTestCase
|
4
4
|
context "testing getter_name()" do
|
5
5
|
should "return proper function names" do
|
6
6
|
assert_equal :hello_world, CsvMadness::Sheet.getter_name( " heLLo __ world " )
|
@@ -10,15 +10,114 @@ class TestCsvMadness < MadTestCase
|
|
10
10
|
|
11
11
|
context "testing default spreadsheet paths" do
|
12
12
|
should "only load existing paths" do
|
13
|
-
|
13
|
+
assert_raises(RuntimeError) do
|
14
14
|
CsvMadness::Sheet.add_search_path( CsvMadness.root.join("rocaganthor") )
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
should "check a search path for files to load" do
|
19
|
-
CsvMadness::Sheet.add_search_path( CsvMadness.root.join("test", "csv") )
|
20
19
|
sheet = CsvMadness.load( "with_nils.csv" )
|
21
20
|
assert sheet.is_a?(CsvMadness::Sheet)
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
context "testing column_types" do
|
25
|
+
should "gracefully handle empty strings for all column_types" do
|
26
|
+
sheet = CsvMadness.load("test_column_types.csv")
|
27
|
+
|
28
|
+
for type, ignore_proc in CsvMadness::Sheet::COLUMN_TYPES
|
29
|
+
sheet.set_column_type( type, type )
|
30
|
+
end
|
31
|
+
|
32
|
+
record = sheet.records[0]
|
33
|
+
|
34
|
+
assert_kind_of String, record.date
|
35
|
+
assert_equal nil, record.number
|
36
|
+
assert_equal nil, record.float
|
37
|
+
|
38
|
+
record = sheet.records[1]
|
39
|
+
assert_equal "12", record.id
|
40
|
+
assert_equal 134.2, record.number
|
41
|
+
assert_equal 100, record.integer
|
42
|
+
assert_equal Time.parse("2013-01-13"), record.date
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "testing add/remove records" do
|
47
|
+
setup do
|
48
|
+
@sheet = CsvMadness.load( "simple.csv", :index => :id )
|
49
|
+
end
|
50
|
+
|
51
|
+
should "add record" do
|
52
|
+
count = @sheet.records.length
|
53
|
+
@sheet.add_record( @sheet.records.first.to_hash )
|
54
|
+
assert_equal count + 1, @sheet.records.length
|
55
|
+
|
56
|
+
for method in [:id, :fname, :lname, :age, :born]
|
57
|
+
assert_equal @sheet.records.first.send(method), @sheet.records.last.send(method)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
should "test remove_record" do
|
62
|
+
count = @sheet.records.length
|
63
|
+
record = @sheet.records.last
|
64
|
+
record_id = record.id
|
65
|
+
|
66
|
+
assert @sheet.fetch(:id, record_id) != nil
|
67
|
+
|
68
|
+
|
69
|
+
@sheet.remove_record( record )
|
70
|
+
assert_equal (count - 1), @sheet.records.length
|
71
|
+
assert @sheet.fetch(:id, record_id) == nil
|
72
|
+
|
73
|
+
count = @sheet.records.length
|
74
|
+
record = @sheet.records[0]
|
75
|
+
record_id = record.id
|
76
|
+
|
77
|
+
@sheet.remove_record( 0 )
|
78
|
+
assert_nil @sheet.fetch(:id, record_id)
|
79
|
+
assert_equal (count - 1), @sheet.records.length
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "testing blanking and splitting of spreadsheet" do
|
84
|
+
should "deliver me a properly blanked spreadsheet (simple)" do
|
85
|
+
sheet = CsvMadness.load( "splitter.csv" )
|
86
|
+
blank_sheet = sheet.blanked
|
87
|
+
|
88
|
+
sheet.length.times do |i|
|
89
|
+
blank_sheet.add_record( sheet.remove_record( 0 ) )
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_zero sheet.length
|
93
|
+
assert_equal 10, blank_sheet.length
|
94
|
+
assert_nil blank_sheet.spreadsheet_file
|
95
|
+
end
|
96
|
+
|
97
|
+
should "deliver me a properly blanked spreadsheet (index)" do
|
98
|
+
sheet = CsvMadness.load( "splitter.csv", :index => [:id] )
|
99
|
+
blank_sheet = sheet.blanked
|
100
|
+
end
|
101
|
+
|
102
|
+
should "split splitter" do
|
103
|
+
sheet = CsvMadness.load( "splitter.csv", :index => [:id, :party] )
|
104
|
+
|
105
|
+
sheets = sheet.split(&:party)
|
106
|
+
|
107
|
+
for party in %w(D I R)
|
108
|
+
assert_equal_length sheets[party], sheet.records.select{|r| r.party == party }
|
109
|
+
end
|
110
|
+
|
111
|
+
assert_includes sheets["D"].index_columns, :id
|
112
|
+
assert_includes sheets["I"].index_columns, :party
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "testing hilarious spreadsheet fails" do
|
117
|
+
should "raise error on forbidden column name" do
|
118
|
+
assert_raises(RuntimeError) do
|
119
|
+
sheet = CsvMadness.load( "forbidden_column.csv" )
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
24
123
|
end
|
metadata
CHANGED
@@ -1,100 +1,38 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_madness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bryce Anderson
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: fun_with_gems
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: shoulda
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rdoc
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
19
|
+
version: 0.0.2
|
51
20
|
- - ~>
|
52
21
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
type: :
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.12'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: bundler
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.3.0
|
70
|
-
type: :development
|
22
|
+
version: '0.0'
|
23
|
+
type: :runtime
|
71
24
|
prerelease: false
|
72
25
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 1.3.0
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: jeweler
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
26
|
requirements:
|
83
|
-
- -
|
27
|
+
- - ! '>='
|
84
28
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
29
|
+
version: 0.0.2
|
91
30
|
- - ~>
|
92
31
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
32
|
+
version: '0.0'
|
94
33
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
34
|
+
name: fun_with_testing
|
96
35
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
36
|
requirements:
|
99
37
|
- - ! '>='
|
100
38
|
- !ruby/object:Gem::Version
|
@@ -102,7 +40,6 @@ dependencies:
|
|
102
40
|
type: :development
|
103
41
|
prerelease: false
|
104
42
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
43
|
requirements:
|
107
44
|
- - ! '>='
|
108
45
|
- !ruby/object:Gem::Version
|
@@ -116,47 +53,51 @@ extra_rdoc_files:
|
|
116
53
|
- LICENSE.txt
|
117
54
|
- README.rdoc
|
118
55
|
files:
|
119
|
-
- ./CHANGELOG.markdown
|
120
|
-
- ./Gemfile
|
121
|
-
- ./README.rdoc
|
122
|
-
- ./Rakefile
|
123
|
-
- ./VERSION
|
124
56
|
- ./lib/csv_madness.rb
|
57
|
+
- ./lib/csv_madness/builder.rb
|
125
58
|
- ./lib/csv_madness/data_accessor_module.rb
|
59
|
+
- ./lib/csv_madness/gem_api.rb
|
126
60
|
- ./lib/csv_madness/record.rb
|
127
61
|
- ./lib/csv_madness/sheet.rb
|
62
|
+
- ./test/csv/forbidden_column.csv
|
128
63
|
- ./test/csv/simple.csv
|
64
|
+
- ./test/csv/splitter.csv
|
65
|
+
- ./test/csv/test_column_types.csv
|
66
|
+
- ./test/csv/with_nils.csv
|
129
67
|
- ./test/helper.rb
|
68
|
+
- ./test/test_builder.rb
|
130
69
|
- ./test/test_csv_madness.rb
|
70
|
+
- ./test/test_merging_columns.rb
|
71
|
+
- ./test/test_reloading_spreadsheet.rb
|
131
72
|
- ./test/test_sheet.rb
|
73
|
+
- CHANGELOG.markdown
|
74
|
+
- Gemfile
|
132
75
|
- LICENSE.txt
|
133
76
|
- README.rdoc
|
77
|
+
- Rakefile
|
78
|
+
- VERSION
|
134
79
|
homepage: http://github.com/darthschmoo/csv_madness
|
135
80
|
licenses:
|
136
81
|
- MIT
|
82
|
+
metadata: {}
|
137
83
|
post_install_message:
|
138
84
|
rdoc_options: []
|
139
85
|
require_paths:
|
140
86
|
- lib
|
141
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
88
|
requirements:
|
144
89
|
- - ! '>='
|
145
90
|
- !ruby/object:Gem::Version
|
146
91
|
version: '0'
|
147
|
-
segments:
|
148
|
-
- 0
|
149
|
-
hash: 1185350757253474800
|
150
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
93
|
requirements:
|
153
94
|
- - ! '>='
|
154
95
|
- !ruby/object:Gem::Version
|
155
96
|
version: '0'
|
156
97
|
requirements: []
|
157
98
|
rubyforge_project:
|
158
|
-
rubygems_version:
|
99
|
+
rubygems_version: 2.2.2
|
159
100
|
signing_key:
|
160
|
-
specification_version:
|
101
|
+
specification_version: 4
|
161
102
|
summary: CSV Madness turns your CSV rows into happycrazy objects.
|
162
103
|
test_files: []
|