tablestakes 0.9.2 → 0.9.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/lib/tablestakes.rb CHANGED
@@ -145,6 +145,34 @@ class Table
145
145
  return self
146
146
  end
147
147
 
148
+ # Append one Table object to another. Raises ArgumentError if the header values and order do not
149
+ # align with the destination Table. Return self if appending an empty table. Return given table if
150
+ # appending to an empty table.
151
+ #
152
+ # ==== Attributes
153
+ # +a_table+:: +Table+ to be added
154
+ #
155
+ # ==== Examples
156
+ # cities.append(more_cities)
157
+ def append(a_table)
158
+ if !a_table.kind_of? Table
159
+ raise ArgumentError, "Argument to append is not a Table"
160
+ end
161
+ if self.empty?
162
+ return a_table
163
+ elsif a_table.empty?
164
+ return self
165
+ end
166
+ if a_table.headers != @headers
167
+ raise ArgumentError, "Argument to append does not have matching headers"
168
+ end
169
+
170
+ a_table.each do |r|
171
+ add_row(r.clone)
172
+ end
173
+ return self
174
+ end
175
+
148
176
  # Add a row to the Table, appending it to the end. Raises ArgumentError if
149
177
  # there are not the correct number of values.
150
178
  #
data/spec/table_spec.rb CHANGED
@@ -81,6 +81,27 @@ describe "Table" do
81
81
  end
82
82
  end
83
83
 
84
+ describe ".append" do
85
+ let(:test1) { Table.new('test.tab') }
86
+ let(:test2) { Table.new('test2.tab') }
87
+ let(:empty) { Table.new() }
88
+ let(:cities) { Table.new('cities.txt') }
89
+
90
+ it "returns a Table" do
91
+ expect(test1.append(test2)).to be_a(Table)
92
+ end
93
+ it "appends itself to an empty table" do
94
+ expect(empty.append(test2).count).to eq(3)
95
+ end
96
+ it "returns itself when appending an empty table" do
97
+ expect(test1.append(empty).count).to eq(3)
98
+ end
99
+ it "raises an ArgumentError when given a table with the wrong headers" do
100
+ expect { test1.append(cities) }.to raise_error(ArgumentError)
101
+ end
102
+ end
103
+
104
+
84
105
  describe ".add_row(s)" do
85
106
  let(:test) { FactoryGirl.build(:table) }
86
107
  let(:empty) { Table.new() }
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.9.2
4
+ version: 0.9.3
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: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2016-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0.7'
103
+ version: '0.8'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0.7'
110
+ version: '0.8'
111
111
  description: A simple implementation of Tables, for use in summing, joining, slicing
112
112
  and dicing data tables
113
113
  email: jbf@pentambic.com
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project:
184
- rubygems_version: 2.2.2
184
+ rubygems_version: 2.4.5.1
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Implementation of in-memory Tables
@@ -193,4 +193,3 @@ test_files:
193
193
  - spec/factories.rb
194
194
  - spec/table_spec.rb
195
195
  - spec/spec_helper.rb
196
- has_rdoc: