octothorpe 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hgignore +1 -0
- data/.hgtags +1 -0
- data/lib/octothorpe.rb +30 -1
- data/spec/octothorpe_spec.rb +58 -5
- data/spec/spec_helper.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44e56895848bd74e1a1c1e0fce48dd52d529bac4
|
4
|
+
data.tar.gz: d930fc76de139a233b1b9695d4f1881fb545168a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fed196557a740921eded0a1ee32e7e2d92400a35a0498db54d98f895bc2af3f2e5cd6085bba9709526f624553ca93aad8041e3633fd711470d788524fd0761
|
7
|
+
data.tar.gz: c0909d019f3509d7a8ab001d470652a0d1929bc67fbb9e9a2d3f3990133bc8d068cd9c5d8e976d01f747b06ba41be5e900b362d268f00f7393f4be464dc1440b
|
data/.hgignore
CHANGED
data/.hgtags
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
a17ae5a3dedd4d2b74b0840a7161e153efd72741 0.2.0
|
data/lib/octothorpe.rb
CHANGED
@@ -32,6 +32,7 @@ require 'forwardable'
|
|
32
32
|
# empty?, has_key?, has_value?, include?
|
33
33
|
# each, each_key, each_value, keys, values
|
34
34
|
# select, map, reject, inject
|
35
|
+
# merge, <, >
|
35
36
|
#
|
36
37
|
class Octothorpe
|
37
38
|
extend Forwardable
|
@@ -41,7 +42,7 @@ class Octothorpe
|
|
41
42
|
def_delegators :@inner_hash, :select, :map, :reject, :inject
|
42
43
|
|
43
44
|
# Gem version number
|
44
|
-
VERSION = '0.
|
45
|
+
VERSION = '0.2.0'
|
45
46
|
|
46
47
|
|
47
48
|
# Generic Octothorpe error class
|
@@ -177,6 +178,34 @@ class Octothorpe
|
|
177
178
|
end
|
178
179
|
|
179
180
|
|
181
|
+
##
|
182
|
+
# Return true if this OT is a subset of the given OT or Hash
|
183
|
+
#
|
184
|
+
def <(other)
|
185
|
+
thisHash = @store.octothorpe_store.to_h
|
186
|
+
otherHash = symbol_hash(other)
|
187
|
+
thisHash < otherHash
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
##
|
192
|
+
# Return true if this OT is a superset of the given OT or Hash
|
193
|
+
#
|
194
|
+
def >(other)
|
195
|
+
thisHash = @store.octothorpe_store.to_h
|
196
|
+
otherHash = symbol_hash(other)
|
197
|
+
thisHash > otherHash
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
##
|
202
|
+
# Inspect exposes a view of the inner hash
|
203
|
+
#
|
204
|
+
def inspect
|
205
|
+
"#<Octothorpe#{@store.octothorpe_store.inspect}>"
|
206
|
+
end
|
207
|
+
|
208
|
+
|
180
209
|
private
|
181
210
|
|
182
211
|
|
data/spec/octothorpe_spec.rb
CHANGED
@@ -4,9 +4,11 @@ describe Octothorpe do
|
|
4
4
|
|
5
5
|
|
6
6
|
before do
|
7
|
-
@hash
|
8
|
-
@hash2
|
9
|
-
@ot
|
7
|
+
@hash = {one: 'a', 'two' => 2, dup: 3, "weird key" => 4}
|
8
|
+
@hash2 = @hash.each_with_object({}) {|(k,v),m| m[k.to_sym] = v }
|
9
|
+
@ot = Octothorpe.new(@hash)
|
10
|
+
@subset = @hash.reject{|k,_| k == :dup }
|
11
|
+
@superset = @hash.dup; @superset[:extra] = 42
|
10
12
|
end
|
11
13
|
|
12
14
|
|
@@ -41,8 +43,8 @@ describe Octothorpe do
|
|
41
43
|
end
|
42
44
|
|
43
45
|
it "throws an exception if passed a parameter or block" do
|
44
|
-
expect{ @ot.>>.
|
45
|
-
expect{ @ot.>>.
|
46
|
+
expect{ @ot.>>.two(1) }.to raise_exception NoMethodError
|
47
|
+
expect{ @ot.>>.two{|x| puts x} }.to raise_exception NoMethodError
|
46
48
|
end
|
47
49
|
|
48
50
|
end
|
@@ -161,6 +163,56 @@ describe Octothorpe do
|
|
161
163
|
end
|
162
164
|
|
163
165
|
|
166
|
+
describe "#>" do
|
167
|
+
|
168
|
+
context 'when passed a hash' do
|
169
|
+
it 'returns true for a subset' do
|
170
|
+
expect( @ot > @subset ).to eq true
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'returns false for a superset' do
|
174
|
+
expect( @ot > @superset ).to eq false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'when passed an OT' do
|
179
|
+
it 'returns true for a subset' do
|
180
|
+
expect( @ot > Octothorpe.new(@subset) ).to eq true
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'returns false for a superset' do
|
184
|
+
expect( @ot > Octothorpe.new(@superset) ).to eq false
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
describe '#<' do
|
192
|
+
|
193
|
+
context 'when passed a hash' do
|
194
|
+
it 'returns false for a subset' do
|
195
|
+
expect( @ot < @subset ).to eq false
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'returns true for a superset' do
|
199
|
+
expect( @ot < @superset ).to eq true
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when passed an OT' do
|
204
|
+
it 'returns false for a subset' do
|
205
|
+
expect( @ot < Octothorpe.new(@subset) ).to eq false
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'returns true for a superset' do
|
209
|
+
expect( @ot < Octothorpe.new(@superset) ).to eq true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
164
216
|
describe "(miscelaneous other stuff)" do
|
165
217
|
# I "imagine" that the actual class uses Forwardable, but the test code
|
166
218
|
# shouldn't know or care about that. In any case, just testing with
|
@@ -178,6 +230,7 @@ describe Octothorpe do
|
|
178
230
|
|
179
231
|
expect( @ot.include?(:two) ).to eq true
|
180
232
|
expect( @ot.include?(:foo) ).not_to eq true
|
233
|
+
|
181
234
|
end
|
182
235
|
|
183
236
|
it "behaves like a hash for a bunch of methods that return an array" do
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,9 @@ RSpec.configure do |config|
|
|
18
18
|
# rspec-expectations config goes here. You can use an alternate
|
19
19
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
20
|
# assertions if you prefer.
|
21
|
+
config.filter_run :focus
|
22
|
+
config.run_all_when_everything_filtered = true
|
23
|
+
|
21
24
|
config.expect_with :rspec do |expectations|
|
22
25
|
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
26
|
# and `failure_message` of custom matchers include text for helper methods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octothorpe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,7 @@ extensions: []
|
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
96
|
- ".hgignore"
|
97
|
+
- ".hgtags"
|
97
98
|
- ".rspec"
|
98
99
|
- Gemfile
|
99
100
|
- LICENSE.txt
|