tablestakes 0.8.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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +218 -0
  3. data/capitals.sorted +50 -0
  4. data/capitals.txt +51 -0
  5. data/cities.txt +290 -0
  6. data/doc/Table.html +1174 -0
  7. data/doc/created.rid +2 -0
  8. data/doc/images/add.png +0 -0
  9. data/doc/images/arrow_up.png +0 -0
  10. data/doc/images/brick.png +0 -0
  11. data/doc/images/brick_link.png +0 -0
  12. data/doc/images/bug.png +0 -0
  13. data/doc/images/bullet_black.png +0 -0
  14. data/doc/images/bullet_toggle_minus.png +0 -0
  15. data/doc/images/bullet_toggle_plus.png +0 -0
  16. data/doc/images/date.png +0 -0
  17. data/doc/images/delete.png +0 -0
  18. data/doc/images/find.png +0 -0
  19. data/doc/images/loadingAnimation.gif +0 -0
  20. data/doc/images/macFFBgHack.png +0 -0
  21. data/doc/images/package.png +0 -0
  22. data/doc/images/page_green.png +0 -0
  23. data/doc/images/page_white_text.png +0 -0
  24. data/doc/images/page_white_width.png +0 -0
  25. data/doc/images/plugin.png +0 -0
  26. data/doc/images/ruby.png +0 -0
  27. data/doc/images/tag_blue.png +0 -0
  28. data/doc/images/tag_green.png +0 -0
  29. data/doc/images/transparent.png +0 -0
  30. data/doc/images/wrench.png +0 -0
  31. data/doc/images/wrench_orange.png +0 -0
  32. data/doc/images/zoom.png +0 -0
  33. data/doc/index.html +71 -0
  34. data/doc/js/darkfish.js +155 -0
  35. data/doc/js/jquery.js +18 -0
  36. data/doc/js/navigation.js +142 -0
  37. data/doc/js/search.js +94 -0
  38. data/doc/js/search_index.js +1 -0
  39. data/doc/js/searcher.js +228 -0
  40. data/doc/rdoc.css +595 -0
  41. data/doc/table_of_contents.html +88 -0
  42. data/lib/tablestakes.rb +407 -0
  43. data/spec/factories.rb +16 -0
  44. data/spec/spec_helper.rb +11 -0
  45. data/spec/table_spec.rb +179 -0
  46. data/test.tab +4 -0
  47. metadata +110 -0
data/spec/factories.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ require 'factory_girl'
4
+
5
+ FactoryGirl.define do
6
+ factory :table do
7
+ rows = []
8
+ rows << ["Name", "Address", "Phone", "Records"]
9
+ rows << ["John", "123 Main", "098-765-4321", "3" ]
10
+ rows << ["Sharon", "123 Main", "098-765-4321", "3" ]
11
+ rows << ["Jerry", "212 Vine", "123-456-7890", "1" ]
12
+
13
+ initialize_with { Table.new(rows) }
14
+ end
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ # spec_helper.rb
2
+ # rspec config
3
+ #
4
+ require 'factory_girl'
5
+
6
+ RSpec.configure do |config|
7
+ config.include FactoryGirl::Syntax::Methods
8
+ #config.include Capybara::DSL
9
+ end
10
+
11
+ FactoryGirl.find_definitions
@@ -0,0 +1,179 @@
1
+ # file: table_spec.rb
2
+ #
3
+ #
4
+ require 'spec_helper'
5
+ require_relative '../lib/tablestakes'
6
+
7
+
8
+ describe "Table" do
9
+
10
+ describe ".new" do
11
+ let(:t) { Table.new('test.tab') }
12
+ let(:s) { Table.new() }
13
+
14
+ it "reads a file and create a table" do
15
+ expect(t).to be_a(Table)
16
+ end
17
+ it "creates a table if no file was given" do
18
+ expect(s).to be_a(Table)
19
+ end
20
+ it "errors when the file is not found" do
21
+ expect{Table.new('sillyfile.txt')}.to raise_error(Errno::ENOENT)
22
+ end
23
+
24
+ end
25
+
26
+ describe ".count" do
27
+ let(:t) { FactoryGirl.build(:table) }
28
+
29
+ it "counts the number of instances in a column" do
30
+ expect(t.count("Address", "123 Main")).to eq(2)
31
+ end
32
+
33
+ it "counts total number of rows when no parameters are given" do
34
+ expect(t.count).to eq(3)
35
+ end
36
+
37
+ it "returns nil if given column is not found" do
38
+ expect(t.count("Silly", "")).to be_nil
39
+ end
40
+
41
+ it "returns zero when instance not found" do
42
+ expect(t.count("Address", "")).to eq(0)
43
+ end
44
+
45
+ it "changes numeric input to a string" do
46
+ expect(t.count("Records", 3)).to eq(2)
47
+ end
48
+ end
49
+
50
+ describe ".tally" do
51
+ let(:t) { FactoryGirl.build(:table) }
52
+
53
+ it "returns a hash" do
54
+ expect(t.tally("Address")).to be_a(Table)
55
+ end
56
+ it "returns nil if the column is not found" do
57
+ expect(t.tally("Silly")).to be_nil
58
+ end
59
+ its "returns a set of keys matched to headers" do
60
+ expect(t.tally("Address").column("Count").each.reduce(:+)).to eq(t.column("Address").length)
61
+ end
62
+ end
63
+
64
+ describe ".where" do
65
+ let(:t) { FactoryGirl.build(:table) }
66
+ let(:cities) { Table.new('cities.txt') }
67
+
68
+ it "returns an instance of Table" do
69
+ expect(t.where("Records", "< '3'")).to be_a(Table)
70
+ end
71
+ #it "selects rows that equal an integer" do
72
+ # expect(t.where("Records", "==3").count).to eq(2)
73
+ #end
74
+ it "selects rows that equal a string" do
75
+ expect(cities.where("State", "=='Texas'").count).to eq(32)
76
+ end
77
+ it "does not select rows that do not meet the given condition" do
78
+ expect(t.where("Records", "=='3'").count("Records", 1)).to eq(0)
79
+ end
80
+ it "returns all rows when no condition is specified" do
81
+ expect(t.where("Records").count).to eq(3)
82
+ end
83
+ it "returns nil when the given condition is not met" do
84
+ expect(t.where("Records", "< '0'")).to be_nil
85
+ end
86
+ end
87
+
88
+ describe ".select" do
89
+ let(:t) { FactoryGirl.build(:table) }
90
+
91
+ it "returns an instance of Table" do
92
+ expect(t.select("Name","Address","Records")).to be_a(Table)
93
+ end
94
+ it "selects columns given as arguments" do
95
+ expect((t.select("Name","Address","Records")).headers).to eq(["Name","Address","Records"])
96
+ end
97
+ it "does not select columns that are not given as arguments" do
98
+ expect((t.select("Name","Address","Records")).headers.include?("Phone")).to be_false
99
+ end
100
+ it "returns nil when the given arguments don't match a column" do
101
+ expect(t.select("Silly")).to be_nil
102
+ end
103
+ end
104
+
105
+ describe ".join" do
106
+ let(:cities) { Table.new('cities.txt') }
107
+ let(:capitals) { Table.new('capitals.txt') }
108
+
109
+ it "returns an instance of Table" do
110
+ expect(capitals.join(cities, "State")).to be_a(Table)
111
+ end
112
+ it "returns only the rows that match" do
113
+ expect(capitals.join(cities, "State").count).to eq(45)
114
+ end
115
+ it "returns the correct rows when tables have matching column names" do
116
+ expect((capitals.join(cities, "State").headers.select { |v| v =="State" }).size).to eq(1)
117
+ end
118
+ it "returns the correct headers when tables do not have matching column names" do
119
+ expect(cities.join(capitals, "City", "Capital").headers).to eq(cities.headers + capitals.headers )
120
+ end
121
+ it "does not return rows that do not match" do
122
+ expect(capitals.join(cities, "State").count("State","West Virginia")).to eq(0)
123
+ end
124
+ it "returns nil when the given arguments don't match a column" do
125
+ expect(capitals.join(cities, "Silly")).to be_nil
126
+ end
127
+ end
128
+
129
+ describe ".sub" do
130
+ let (:cities) { Table.new('cities.txt') }
131
+
132
+ it "returns an instance of Table" do
133
+ expect(cities.sub("State", /Jersey/, "York")).to be_a(Table)
134
+ end
135
+ it "substitutes the values in a given field" do
136
+ expect((cities.sub("State", /Jersey/, "York")).count("State", "New York")).to eq(9)
137
+ end
138
+ it "returns nil when the given arguments don't match a column" do
139
+ expect(cities.sub("Silly", /NJ/, "NY")).to be_nil
140
+ end
141
+ end
142
+
143
+ describe ".union" do
144
+ let (:cities) { Table.new('cities.txt') }
145
+ let(:capitals) { Table.new('capitals.txt') }
146
+
147
+ it "returns an instance of Array" do
148
+ expect(capitals.union(cities, "Capital", "City")).to be_a(Array)
149
+ end
150
+ it "returns instances in table 1, but not in table 2" do
151
+ expect(capitals.union(cities,"Capital", "City")).to include("Montpelier")
152
+ end
153
+ it "returns instances in table 2, but not in table 1" do
154
+ expect(capitals.union(cities,"Capital", "City")).to include("El Monte")
155
+ end
156
+ it "returns nil for invalid values" do
157
+ expect(capitals.union(cities,"Silly")).to be_nil
158
+ end
159
+ end
160
+
161
+ describe ".intersect" do
162
+ let (:cities) { Table.new('cities.txt') }
163
+ let(:capitals) { Table.new('capitals.txt') }
164
+
165
+ it "returns an instance of Array" do
166
+ expect(capitals.intersect(cities, "Capital", "City")).to be_a(Array)
167
+ end
168
+ it "does not return instances in table 1, but not in table 2" do
169
+ expect(capitals.intersect(cities,"Capital", "City")).not_to include("Montpelier")
170
+ end
171
+ it "does not return instances in table 2, but not in table 1" do
172
+ expect(capitals.intersect(cities,"Capital", "City")).not_to include("El Monte")
173
+ end
174
+ it "returns nil for invalid values" do
175
+ expect(capitals.intersect(cities,"Silly")).to be_nil
176
+ end
177
+ end
178
+
179
+ end
data/test.tab ADDED
@@ -0,0 +1,4 @@
1
+ Name Address Phone Records
2
+ John 123 Main 098-765-4321 3
3
+ Sharon 123 Main 098-765-4321 3
4
+ Jerry 212 Vine 123-456-7890 1
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tablestakes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.3
5
+ platform: ruby
6
+ authors:
7
+ - J.B. Folkerts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A simple implementation of Tables, for use in summing, joining, slicing
28
+ and dicing data tables
29
+ email: jbf@pentambic.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/tablestakes.rb
35
+ - doc/created.rid
36
+ - doc/images/add.png
37
+ - doc/images/arrow_up.png
38
+ - doc/images/brick.png
39
+ - doc/images/brick_link.png
40
+ - doc/images/bug.png
41
+ - doc/images/bullet_black.png
42
+ - doc/images/bullet_toggle_minus.png
43
+ - doc/images/bullet_toggle_plus.png
44
+ - doc/images/date.png
45
+ - doc/images/delete.png
46
+ - doc/images/find.png
47
+ - doc/images/loadingAnimation.gif
48
+ - doc/images/macFFBgHack.png
49
+ - doc/images/package.png
50
+ - doc/images/page_green.png
51
+ - doc/images/page_white_text.png
52
+ - doc/images/page_white_width.png
53
+ - doc/images/plugin.png
54
+ - doc/images/ruby.png
55
+ - doc/images/tag_blue.png
56
+ - doc/images/tag_green.png
57
+ - doc/images/transparent.png
58
+ - doc/images/wrench.png
59
+ - doc/images/wrench_orange.png
60
+ - doc/images/zoom.png
61
+ - doc/index.html
62
+ - doc/js/darkfish.js
63
+ - doc/js/jquery.js
64
+ - doc/js/navigation.js
65
+ - doc/js/search.js
66
+ - doc/js/searcher.js
67
+ - doc/js/search_index.js
68
+ - doc/rdoc.css
69
+ - doc/Table.html
70
+ - doc/table_of_contents.html
71
+ - README.md
72
+ - test.tab
73
+ - cities.txt
74
+ - capitals.txt
75
+ - capitals.sorted
76
+ - spec/factories.rb
77
+ - spec/table_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: http://rubygems.org/gems/tablestakes
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.0.14
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Implementation of in-memory Tables
103
+ test_files:
104
+ - test.tab
105
+ - cities.txt
106
+ - capitals.txt
107
+ - capitals.sorted
108
+ - spec/factories.rb
109
+ - spec/table_spec.rb
110
+ - spec/spec_helper.rb