tablestakes 0.8.5 → 0.9.0

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/spec/spec_helper.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  # spec_helper.rb
2
2
  # rspec config
3
3
  #
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+ SimpleCov.start
12
+
4
13
  require 'factory_girl'
5
14
 
6
15
  RSpec.configure do |config|
data/spec/table_spec.rb CHANGED
@@ -123,11 +123,15 @@ describe "Table" do
123
123
  it "raises an ArgumentError when given an index that is out of bounds" do
124
124
  expect { test.del_row(10) }.to raise_error(ArgumentError)
125
125
  end
126
+ it "raises an ArgumentError when called on an empty table" do
127
+ expect { empty.del_row(0) }.to raise_error(ArgumentError)
128
+ end
126
129
  end
127
130
 
128
131
  describe ".count" do
129
132
  let(:t) { FactoryGirl.build(:table) }
130
-
133
+ let(:empty) { Table.new() }
134
+
131
135
  it "counts the number of instances in a column" do
132
136
  expect(t.count("Address", "123 Main")).to eq(2)
133
137
  end
@@ -136,13 +140,17 @@ describe "Table" do
136
140
  expect(t.count).to eq(3)
137
141
  end
138
142
 
139
- it "returns nil if given column is not found" do
140
- expect(t.count("Silly", "")).to be_nil
143
+ it "raises ArgumentError if given column is not found" do
144
+ expect {t.count("Silly", "") }.to raise_error(ArgumentError)
141
145
  end
142
146
 
143
147
  it "returns zero when instance not found" do
144
148
  expect(t.count("Address", "")).to eq(0)
145
149
  end
150
+
151
+ it "returns zero on an empty table" do
152
+ expect(empty.count).to eq(0)
153
+ end
146
154
 
147
155
  it "changes numeric input to a string" do
148
156
  expect(t.count("Records", 3)).to eq(2)
@@ -155,8 +163,8 @@ describe "Table" do
155
163
  it "returns a hash" do
156
164
  expect(t.tally("Address")).to be_a(Table)
157
165
  end
158
- it "returns nil if the column is not found" do
159
- expect(t.tally("Silly")).to be_nil
166
+ it "raises ArgumentError if the column is not found" do
167
+ expect { t.tally("Silly") }.to raise_error(ArgumentError)
160
168
  end
161
169
  its "returns a set of keys matched to headers" do
162
170
  expect(t.tally("Address").column("Count").each.reduce(:+)).to eq(t.column("Address").length)
@@ -182,8 +190,8 @@ describe "Table" do
182
190
  it "returns all rows when no condition is specified" do
183
191
  expect(t.where("Records").count).to eq(3)
184
192
  end
185
- it "returns nil when the given condition is not met" do
186
- expect(t.where("Records", "< '0'")).to be_nil
193
+ it "returns an empty table when the given condition is not met" do
194
+ expect(t.where("Records", "< '0'")).to be_empty
187
195
  end
188
196
  end
189
197
 
@@ -199,8 +207,8 @@ describe "Table" do
199
207
  it "does not select columns that are not given as arguments" do
200
208
  expect((t.select("Name","Address","Records")).headers.include?("Phone")).to be_false
201
209
  end
202
- it "returns nil when the given arguments don't match a column" do
203
- expect(t.select("Silly")).to be_nil
210
+ it "raise ArgumentError when the given arguments don't match a column" do
211
+ expect { t.select("Silly") }.to raise_error(ArgumentError)
204
212
  end
205
213
  end
206
214
 
@@ -223,8 +231,8 @@ describe "Table" do
223
231
  it "does not return rows that do not match" do
224
232
  expect(capitals.join(cities, "State").count("State","West Virginia")).to eq(0)
225
233
  end
226
- it "returns nil when the given arguments don't match a column" do
227
- expect(capitals.join(cities, "Silly")).to be_nil
234
+ it "raises ArgumentError when the given arguments don't match a column" do
235
+ expect {capitals.join(cities, "Silly") }.to raise_error(ArgumentError)
228
236
  end
229
237
  end
230
238
 
@@ -237,8 +245,8 @@ describe "Table" do
237
245
  it "substitutes the values in a given field" do
238
246
  expect((cities.sub("State", /Jersey/, "York")).count("State", "New York")).to eq(9)
239
247
  end
240
- it "returns nil when the given arguments don't match a column" do
241
- expect(cities.sub("Silly", /NJ/, "NY")).to be_nil
248
+ it "raises ArgumentError when the given arguments don't match a column" do
249
+ expect {cities.sub("Silly", /NJ/, "NY") }.to raise_error(ArgumentError)
242
250
  end
243
251
  end
244
252
 
@@ -255,8 +263,8 @@ describe "Table" do
255
263
  it "returns instances in table 2, but not in table 1" do
256
264
  expect(capitals.union(cities,"Capital", "City")).to include("El Monte")
257
265
  end
258
- it "returns nil for invalid values" do
259
- expect(capitals.union(cities,"Silly")).to be_nil
266
+ it "raises ArgumentError for invalid values" do
267
+ expect {capitals.union(cities,"Silly") }.to raise_error(ArgumentError)
260
268
  end
261
269
  end
262
270
 
@@ -273,9 +281,55 @@ describe "Table" do
273
281
  it "does not return instances in table 2, but not in table 1" do
274
282
  expect(capitals.intersect(cities,"Capital", "City")).not_to include("El Monte")
275
283
  end
276
- it "returns nil for invalid values" do
277
- expect(capitals.intersect(cities,"Silly")).to be_nil
284
+ it "raises ArgumentError for invalid values" do
285
+ expect {capitals.intersect(cities,"Silly") }.to raise_error(ArgumentError)
286
+ end
287
+ end
288
+
289
+ describe ".top/.bottom" do
290
+ let (:cities) { Table.new('cities.txt') }
291
+
292
+ it "returns a Table" do
293
+ expect(cities.top("State")).to be_a(Table)
294
+ end
295
+ it "returns the top element" do
296
+ expect(cities.top("State").row(0)[0]).to eq("California")
297
+ end
298
+ it "returns the top 10 elements when requested" do
299
+ expect(cities.top("State", 10).count).to eq(10)
300
+ end
301
+ it "returns an ArgumentError when invalid number of elements" do
302
+ expect {cities.top }.to raise_error(ArgumentError)
278
303
  end
304
+ it "returns the bottom element" do
305
+ expect(cities.bottom("State").row(0)[1]).to eq("1")
306
+ end
307
+ end
308
+
309
+ describe ".sort" do
310
+ let(:test) { Table.new('test.tab') }
311
+ let(:empty) { Table.new() }
312
+
313
+
314
+ it "returns an instance of Table" do
315
+ expect(test.sort("Records").row(0)).to eq(["Jerry", "212 Vine", "123-456-7890", "1"])
316
+ end
317
+ it "can sort by first element (default)" do
318
+ expect(test.sort.row(0)).to eq(["Jerry", "212 Vine", "123-456-7890", "1"])
319
+ end
320
+ it "can sort by given element" do
321
+ expect(test.sort(3).row(0)).to eq(["Jerry", "212 Vine", "123-456-7890", "1"])
322
+ end
323
+ it "can sort by given header name" do
324
+ expect(test.sort("Records").row(0)).to eq(["Jerry", "212 Vine", "123-456-7890", "1"])
325
+ end
326
+ it "returns empty Table when given empty Table" do
327
+ expect(Table.new().sort).to be_empty
328
+ end
329
+ it "accepts a block as input" do
330
+ expect(test.sort("Name") { |a,b| b <=> a }.row(0)[0]).to eq("Sharon")
331
+ end
332
+
279
333
  end
280
334
 
281
335
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tablestakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.B. Folkerts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-19 00:00:00.000000000 Z
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.14.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
- version: '0'
26
+ version: 2.14.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: factory_girl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.4.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.0
27
69
  description: A simple implementation of Tables, for use in summing, joining, slicing
28
70
  and dicing data tables
29
71
  email: jbf@pentambic.com
@@ -65,6 +107,7 @@ files:
65
107
  - doc/js/search.js
66
108
  - doc/js/searcher.js
67
109
  - doc/js/search_index.js
110
+ - doc/OrderedRow.html
68
111
  - doc/rdoc.css
69
112
  - doc/Table.html
70
113
  - doc/table_of_contents.html