tabular 0.2.2 → 0.2.3
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 +1 -0
- data/VERSION +1 -1
- data/lib/tabular/table.rb +8 -2
- data/tabular.gemspec +2 -2
- data/test/table_test.rb +25 -6
- metadata +3 -3
data/README
CHANGED
@@ -62,6 +62,7 @@ There's basic test coverage. More comprehensive test coverage needs to be extrac
|
|
62
62
|
|
63
63
|
Changes
|
64
64
|
-------
|
65
|
+
0.2.3 Add :except option for delete_homogenous_columns!
|
65
66
|
0.2.1 Documentation!
|
66
67
|
0.2.0 Add several new features that break previous API
|
67
68
|
* New public accessors for Table, Columns, Row, and Column
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/tabular/table.rb
CHANGED
@@ -135,10 +135,16 @@ module Tabular
|
|
135
135
|
end
|
136
136
|
|
137
137
|
# Remove all columns that contain the same value in all rows
|
138
|
-
def delete_homogenous_columns!
|
138
|
+
def delete_homogenous_columns!(*_options)
|
139
139
|
return if rows.size < 2
|
140
140
|
|
141
|
-
|
141
|
+
if _options.first && _options.first[:except]
|
142
|
+
exceptions = _options.first[:except]
|
143
|
+
else
|
144
|
+
exceptions = []
|
145
|
+
end
|
146
|
+
|
147
|
+
(columns.map(&:key) - exceptions).each do |key|
|
142
148
|
value = rows.first[key]
|
143
149
|
if rows.all? { |row| row[key] == value }
|
144
150
|
delete_column key
|
data/tabular.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "tabular"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Scott Willson"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-06-12"
|
13
13
|
s.description = "Tabular is a Ruby library for reading, writing, and manipulating CSV, tab-delimited and Excel data."
|
14
14
|
s.email = "scott.willson@gmail.cpm"
|
15
15
|
s.extra_rdoc_files = [
|
data/test/table_test.rb
CHANGED
@@ -113,10 +113,10 @@ module Tabular
|
|
113
113
|
def test_delete_blank_columns_empty_table
|
114
114
|
Table.new.delete_blank_columns!
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def test_delete_homogenous_columns
|
118
118
|
Table.new.delete_homogenous_columns!
|
119
|
-
|
119
|
+
|
120
120
|
data = [
|
121
121
|
[ "nom", "equipe", "homme", "age" ],
|
122
122
|
[ "Hinault", "", "true", "30" ],
|
@@ -126,18 +126,37 @@ module Tabular
|
|
126
126
|
|
127
127
|
table = Table.new
|
128
128
|
table.rows = data
|
129
|
-
|
129
|
+
|
130
130
|
table.delete_homogenous_columns!
|
131
|
-
|
131
|
+
|
132
132
|
assert_equal 3, table.rows.size, "size"
|
133
133
|
assert_equal({ :nom => "Hinault", :age => "30" }, table.rows[0].to_hash)
|
134
134
|
assert_equal({ :nom => "Lemond", :age => "20" }, table.rows[1].to_hash)
|
135
135
|
assert_equal({ :nom => "Hinault", :age => "30" }, table.rows[2].to_hash)
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
|
+
def test_delete_homogenous_columns_with_exceptions
|
139
|
+
data = [
|
140
|
+
[ "nom", "equipe", "homme", "age" ],
|
141
|
+
[ "Hinault", "", "true", "30" ],
|
142
|
+
[ "Lemond", "", "true", "20" ],
|
143
|
+
[ "Hinault", "", "true", "30" ]
|
144
|
+
]
|
145
|
+
|
146
|
+
table = Table.new
|
147
|
+
table.rows = data
|
148
|
+
|
149
|
+
table.delete_homogenous_columns!(:except => [ :homme ])
|
150
|
+
|
151
|
+
assert_equal 3, table.rows.size, "size"
|
152
|
+
assert_equal({ :nom => "Hinault", :homme => "true", :age => "30" }, table.rows[0].to_hash)
|
153
|
+
assert_equal({ :nom => "Lemond", :homme => "true", :age => "20" }, table.rows[1].to_hash)
|
154
|
+
assert_equal({ :nom => "Hinault", :homme => "true", :age => "30" }, table.rows[2].to_hash)
|
155
|
+
end
|
156
|
+
|
138
157
|
def test_delete_homogenous_columns_single_row
|
139
158
|
Table.new.delete_homogenous_columns!
|
140
|
-
|
159
|
+
|
141
160
|
data = [
|
142
161
|
[ "nom", "equipe", "homme", "age" ],
|
143
162
|
[ "Hinault", "", "true", "30" ],
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: tabular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Scott Willson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-ole
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements:
|
106
106
|
- - ! '>='
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
hash:
|
108
|
+
hash: -3774209472319909439
|
109
109
|
segments:
|
110
110
|
- 0
|
111
111
|
version: '0'
|