rangehash 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/rangehash.rb +7 -2
- data/spec/rangehash_spec.rb +12 -7
- data.tar.gz.sig +0 -0
- metadata +4 -4
- metadata.gz.sig +0 -0
data/History.txt
CHANGED
data/lib/rangehash.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module Rangehash
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.4'
|
6
6
|
end
|
7
7
|
|
8
8
|
class RangeHash < Hash
|
@@ -19,6 +19,11 @@ class RangeHash < Hash
|
|
19
19
|
raise IndexError, "key " + key.to_s + " not found" if not block_given?
|
20
20
|
end
|
21
21
|
|
22
|
+
def assoc(key)
|
23
|
+
found = find_pair(key)
|
24
|
+
found.empty? ? nil : found.first
|
25
|
+
end
|
26
|
+
|
22
27
|
def key?(key)
|
23
28
|
found = find_pair(key)
|
24
29
|
!(found.empty?)
|
@@ -40,7 +45,7 @@ class RangeHash < Hash
|
|
40
45
|
|
41
46
|
private
|
42
47
|
def find_pair(key)
|
43
|
-
|
48
|
+
each.select {|k, v| (k == key || k === key)}
|
44
49
|
end
|
45
50
|
|
46
51
|
def find_value(key)
|
data/spec/rangehash_spec.rb
CHANGED
@@ -60,6 +60,18 @@ describe RangeHash do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
describe ".assoc" do
|
64
|
+
it "handle reanges specially" do
|
65
|
+
rh[2..4] = :foo
|
66
|
+
rh.assoc(3).should == [(2..4), :foo]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns nil if key not found" do
|
70
|
+
rh[2..4] = :foo
|
71
|
+
rh.assoc(42).should be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
63
75
|
describe ".fetch" do
|
64
76
|
it "handles ranges" do
|
65
77
|
rh[2..4] = :foo
|
@@ -123,13 +135,6 @@ describe RangeHash do
|
|
123
135
|
end
|
124
136
|
end
|
125
137
|
|
126
|
-
describe ".index" do
|
127
|
-
it "handles ranges" do
|
128
|
-
rh[2..4] = :foo
|
129
|
-
rh.index(:foo).should == (2..4)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
138
|
describe ".sorted_keys" do
|
134
139
|
it "allows retrieval of sorted keys" do
|
135
140
|
rh[10..20] = :foo
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rangehash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Simpson
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
rPnJW2hNpPLFrA==
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2011-04-
|
39
|
+
date: 2011-04-28 00:00:00 -04:00
|
40
40
|
default_executable:
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
metadata.gz.sig
CHANGED
Binary file
|