hashery 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.ruby +57 -92
  2. data/.yardopts +8 -0
  3. data/COPYING.rdoc +45 -0
  4. data/HISTORY.rdoc +18 -0
  5. data/QED.rdoc +1 -0
  6. data/README.rdoc +42 -16
  7. data/lib/hashery.rb +16 -9
  8. data/lib/hashery.yml +57 -92
  9. data/lib/hashery/association.rb +3 -1
  10. data/lib/hashery/basic_object.rb +74 -0
  11. data/lib/hashery/basic_struct.rb +288 -1
  12. data/lib/hashery/basicobject.rb +1 -74
  13. data/lib/hashery/basicstruct.rb +1 -280
  14. data/lib/hashery/casting_hash.rb +171 -1
  15. data/lib/hashery/castinghash.rb +1 -171
  16. data/lib/hashery/core_ext.rb +82 -0
  17. data/lib/hashery/dictionary.rb +3 -0
  18. data/lib/hashery/fuzzy_hash.rb +154 -1
  19. data/lib/hashery/fuzzyhash.rb +1 -154
  20. data/lib/hashery/ini.rb +3 -2
  21. data/lib/hashery/key_hash.rb +186 -0
  22. data/lib/hashery/keyhash.rb +1 -0
  23. data/lib/hashery/linked_list.rb +195 -1
  24. data/lib/hashery/linkedlist.rb +1 -195
  25. data/lib/hashery/lru_hash.rb +273 -1
  26. data/lib/hashery/lruhash.rb +1 -273
  27. data/lib/hashery/open_cascade.rb +99 -1
  28. data/lib/hashery/open_hash.rb +77 -1
  29. data/lib/hashery/opencascade.rb +1 -99
  30. data/lib/hashery/openhash.rb +1 -77
  31. data/lib/hashery/ordered_hash.rb +168 -1
  32. data/lib/hashery/orderedhash.rb +1 -167
  33. data/lib/hashery/property_hash.rb +97 -1
  34. data/lib/hashery/propertyhash.rb +1 -97
  35. data/lib/hashery/query_hash.rb +35 -1
  36. data/lib/hashery/queryhash.rb +1 -35
  37. data/lib/hashery/stash.rb +3 -174
  38. data/lib/hashery/static_hash.rb +48 -1
  39. data/lib/hashery/statichash.rb +1 -48
  40. data/qed/06_opencascade.rdoc +12 -12
  41. data/test/case_association.rb +29 -15
  42. data/test/case_basicstruct.rb +192 -0
  43. data/test/case_dictionary.rb +149 -109
  44. data/test/case_keyhash.rb +175 -0
  45. data/test/case_opencascade.rb +89 -43
  46. data/test/case_openhash.rb +15 -11
  47. metadata +85 -78
  48. data/LICENSE +0 -206
  49. data/NOTICE +0 -11
  50. data/lib/hashery/sparse_array.rb +0 -1
  51. data/lib/hashery/sparsearray.rb +0 -577
  52. data/test/case_openobject.rb +0 -130
  53. data/test/case_sparsearray.rb +0 -316
  54. data/test/case_stash.rb +0 -131
@@ -0,0 +1,175 @@
1
+ require 'lemon'
2
+ require 'ae'
3
+ require 'ae/pry'
4
+
5
+ require 'hashery/key_hash'
6
+
7
+ testcase KeyHash do
8
+
9
+ class_method :[] do
10
+ test 'class level fetch' do
11
+ s = KeyHash[:a=>1, :b=>2]
12
+ assert(s)
13
+ end
14
+ end
15
+
16
+ method :[] do
17
+ test 'instance level fetch' do
18
+ s = KeyHash[:a=>1, :b=>2]
19
+ s[:a].assert == 1
20
+ s[:b].assert == 2
21
+ s['a'].assert == 1
22
+ s['b'].assert == 2
23
+ end
24
+ end
25
+
26
+ method :[]= do
27
+ test do
28
+ s = KeyHash.new
29
+ s[:a] = 1
30
+ s[:b] = 2
31
+ s[:a].assert == 1
32
+ s[:b].assert == 2
33
+ s['a'].assert == 1
34
+ s['b'].assert == 2
35
+ end
36
+ end
37
+
38
+ method :initialize do
39
+ test do
40
+ s = KeyHash.new
41
+ assert(s)
42
+ end
43
+ end
44
+
45
+ method :to_hash do
46
+ test do
47
+ s = KeyHash[:a=>1, :b=>2]
48
+ s.to_hash.assert == {'a'=>1, 'b'=>2}
49
+ end
50
+ end
51
+
52
+ method :to_h do
53
+ test do
54
+ s = KeyHash[:a=>1, :b=>2]
55
+ s.to_h.assert == {'a'=>1, 'b'=>2}
56
+ end
57
+ end
58
+
59
+ method :replace do
60
+ test do
61
+ s = KeyHash.new
62
+ s.replace(:a=>1, :b=>2)
63
+ s.to_h.assert == {'a'=>1, 'b'=>2}
64
+ end
65
+ end
66
+
67
+ method :delete do
68
+ test do
69
+ s = KeyHash[:a=>1, :b=>2]
70
+ s.delete(:a)
71
+ s.to_h.assert == {'b'=>2}
72
+ end
73
+ end
74
+
75
+ method :each do
76
+ test do
77
+ s = KeyHash[:a=>1, :b=>2]
78
+ s.each do |k,v|
79
+ String.assert === k
80
+ end
81
+ end
82
+ end
83
+
84
+ method :store do
85
+ test do
86
+ s = KeyHash.new
87
+ s.store(:a, 1)
88
+ s.to_h.assert == {'a'=>1}
89
+ end
90
+ end
91
+
92
+ method :update do
93
+ test do
94
+ s1 = KeyHash[:a=>1,:b=>2]
95
+ s2 = KeyHash[:c=>3,:d=>4]
96
+ s1.update(s2)
97
+ s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
98
+ end
99
+ end
100
+ require 'ae'
101
+ method :rekey do
102
+ test do
103
+ s = KeyHash[:a=>1,:b=>2,:c=>3]
104
+ x = s.rekey{ |k| k.upcase }
105
+ x.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
106
+ end
107
+ end
108
+
109
+ method :rekey! do
110
+ test do
111
+ s = KeyHash[:a=>1,:b=>2,:c=>3]
112
+ s.rekey!{ |k| k.upcase }
113
+ s.to_h.assert == {'A'=>1,'B'=>2,'C'=>3}
114
+ end
115
+ end
116
+
117
+ method :key? do
118
+ test do
119
+ s = KeyHash[:a=>1]
120
+ s.assert.key?(:a)
121
+ s.assert.key?('a')
122
+ end
123
+ end
124
+
125
+ method :has_key? do
126
+ test do
127
+ s = KeyHash[:a=>1]
128
+ s.assert.has_key?(:a)
129
+ s.assert.has_key?('a')
130
+ end
131
+ end
132
+
133
+ method :<< do
134
+ test do
135
+ s = KeyHash.new
136
+ s << [:a, 1]
137
+ s << [:b, 2]
138
+ s.to_h.assert == {'a'=>1, 'b'=>2}
139
+ end
140
+ end
141
+
142
+ method :merge! do
143
+ test do
144
+ s1 = KeyHash[:a=>1,:b=>2]
145
+ s2 = KeyHash[:c=>3,:d=>4]
146
+ s1.merge!(s2)
147
+ s1.to_h.assert == {'a'=>1,'b'=>2,'c'=>3,'d'=>4}
148
+ end
149
+ end
150
+
151
+ method :values_at do
152
+ test do
153
+ s = KeyHash[:a=>1,:b=>2,:c=>3]
154
+ s.values_at(:a, :b).assert == [1,2]
155
+ s.values_at('a','b').assert == [1,2]
156
+ end
157
+ end
158
+
159
+ method :fetch do
160
+ test do
161
+ s = KeyHash[:a=>1,:b=>2,:c=>3]
162
+ s.fetch(:a).assert == 1
163
+ s.fetch('a').assert == 1
164
+ end
165
+ end
166
+
167
+ method :convert_key do
168
+ test do
169
+ s = KeyHash.new
170
+ s.pry.convert_key(:a).assert == 'a'
171
+ end
172
+ end
173
+
174
+ end
175
+
@@ -1,68 +1,114 @@
1
- require 'hashery/opencascade'
1
+ require 'lemon'
2
+ require 'ae'
2
3
  require 'ae/legacy' # bacause imitation BasicObject sucks
3
4
 
4
- TestCase OpenCascade do
5
+ require 'hashery/open_cascade'
5
6
 
6
- Unit :new do
7
- o = OpenCascade.new(:a=>1)
8
- assert_equal(OpenCascade.new, o.assert)
7
+ testcase OpenCascade do
8
+ include AE::Legacy::Assertions
9
+
10
+ class_method :new do
11
+ OpenCascade.new(:a=>1)
9
12
  end
10
13
 
11
- Unit :[] => "initialization" do
12
- o = OpenCascade[:a=>1,:b=>2]
13
- assert_equal(1, o.a)
14
- assert_equal(2, o.b)
14
+ class_method :[] do
15
+ test "hash" do
16
+ o = OpenCascade[:a=>1,:b=>2]
17
+ assert_equal(1, o.a)
18
+ assert_equal(2, o.b)
19
+ end
20
+ test "hash in hash" do
21
+ o = OpenCascade[:a=>1,:b=>2,:c=>{:x=>9}]
22
+ assert_equal(9, o.c.x)
23
+ end
24
+ test "hash in hash in hash" do
25
+ h = {:a=>1,:x=>{:y=>{:z=>1}}}
26
+ c = OpenCascade[h]
27
+ assert_equal(1, c.x.y.z)
28
+ end
15
29
  end
16
30
 
17
- Unit :[] => "mutlt-depth lookup" do
18
- o = OpenCascade[:a=>1,:b=>2,:c=>{:x=>9}]
19
- assert_equal(9, o.c.x)
31
+ method :[] do
32
+ test "basic assignment" do
33
+ o = OpenCascade.new
34
+ o[:a] = 1
35
+ assert_equal(1, o.a)
36
+ end
20
37
  end
21
38
 
22
- Unit :[] => "basic assignment" do
23
- o = OpenCascade.new
24
- o[:a] = 1
25
- assert_equal(1, o.a)
39
+ method :[]= do
40
+ test "basic assignment with primed OpenCascade" do
41
+ o = OpenCascade[:a=>1]
42
+ o[:b] = 2
43
+ o.to_h.assert == {:a=>1,:b=>2}
44
+ end
26
45
  end
27
46
 
28
- Unit :[] => "basic assignment with primed OpenCascade" do
29
- o = OpenCascade[:a=>1]
30
- o[:b] = 2
31
- assert_equal({:a=>1,:b=>2}, o.to_h)
47
+ method :to_a do
48
+ test do
49
+ o = OpenCascade[:a=>1,:b=>2]
50
+ a = o.to_a
51
+ a.assert.include?([:a,1])
52
+ a.assert.include?([:b,2])
53
+ a.size.assert == 2
54
+ end
32
55
  end
33
56
 
34
- Unit :to_a do
35
- o = OpenCascade[:a=>1,:b=>2]
36
- assert_equal([[:a,1], [:b,2]], o.to_a)
57
+ method :to_h do
58
+ test do
59
+ o = OpenCascade[:a=>1]
60
+ assert_equal({:a=>1}, o.to_h)
61
+ end
37
62
  end
38
63
 
39
- Unit :to_h do
40
- o = OpenCascade[:a=>1]
41
- assert_equal({:a=>1}, o.to_h)
64
+ method :merge! do
65
+ test do
66
+ o = OpenCascade[:f0=>"f0"]
67
+ h = { :h0=>"h0" }
68
+ r = OpenCascade[:f0=>"f0", :h0=>"h0"]
69
+ assert_equal(r, o.merge!(h))
70
+ assert_equal({:f0=>"f0", :h0=>"h0"}, h.merge(o))
71
+ end
42
72
  end
43
73
 
44
- Unit :merge! do
45
- o = OpenCascade[:f0=>"f0"]
46
- h = { :h0=>"h0" }
47
- r = OpenCascade[:f0=>"f0", :h0=>"h0"]
48
- assert_equal(r, o.merge!(h))
49
- assert_equal({:f0=>"f0", :h0=>"h0"}, h.merge(o))
74
+ method :update do
75
+ test do
76
+ o = OpenCascade[:f1=>"f1"]
77
+ o.update(:h1=>"h1")
78
+ o.assert == OpenCascade[:f1=>"f1", :h1=>"h1"]
79
+ end
50
80
  end
51
81
 
52
- Unit :update! do
53
- o = OpenCascade[:f1=>"f1"]
54
- h = { :h1=>"h1" }
55
- o.update!(h)
56
- h.update(o)
57
- assert_equal(OpenCascade[:f1=>"f1", :h1=>"h1"], o)
58
- assert_equal({:f1=>"f1", :h1=>"h1"}, h)
82
+ method :method_missing do
83
+ test "writer and reader" do
84
+ o = OpenCascade.new
85
+ 10.times{ |i| o.__send__("n#{i}=", 1 ) }
86
+ 10.times{ |i| assert_equal(1, o.__send__("n#{i}")) }
87
+ end
59
88
  end
60
89
 
61
- Unit :method_missing => "writer and reader" do
62
- o = OpenCascade.new
63
- 10.times{ |i| o.__send__("n#{i}=", 1 ) }
64
- 10.times{ |i| assert_equal(1, o.__send__("n#{i}")) }
90
+ method :<< do
91
+ test do
92
+ c = OpenCascade.new
93
+ c << [:x,8]
94
+ c << [:y,9]
95
+
96
+ assert_equal(8, c.x)
97
+ assert_equal(9, c.y)
98
+ end
65
99
  end
66
100
 
67
101
  end
68
102
 
103
+ testcase Hash do
104
+
105
+ method :update do
106
+ test "hash can be updated by OpenCascade" do
107
+ o = OpenCascade[:f1=>"f1"]
108
+ h = {:h1=>"h1"}
109
+ h.update(o)
110
+ h.assert == {:f1=>"f1", :h1=>"h1"}
111
+ end
112
+ end
113
+
114
+ end
@@ -1,17 +1,21 @@
1
- require 'hashery/openhash'
1
+ require 'lemon'
2
+ require 'ae'
2
3
 
3
- TestCase OpenHash do
4
+ require 'hashery/open_hash'
4
5
 
5
- Unit :new do
6
- o = OpenHash.new(:a=>1, :b=>2)
7
- o.a.assert == 1
8
- o.b.assert == 2
9
- end
6
+ testcase OpenHash do
10
7
 
11
- Unit :new do
12
- o = OpenHash.new(:a=>1, :b=>2)
13
- o.a.assert == 1
14
- o.b.assert == 2
8
+ class_method :new do
9
+ test do
10
+ o = OpenHash.new(:a=>1, :b=>2)
11
+ o.a.assert == 1
12
+ o.b.assert == 2
13
+ end
14
+ test do
15
+ o = OpenHash.new(:a=>1, :b=>2)
16
+ o.a.assert == 1
17
+ o.b.assert == 2
18
+ end
15
19
  end
16
20
 
17
21
  end
metadata CHANGED
@@ -1,16 +1,11 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hashery
3
- version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 4
9
- - 0
10
- version: 1.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - Thomas Sawyer
7
+ authors:
8
+ - Trans
14
9
  - Kirk Haines
15
10
  - Robert Klemme
16
11
  - Jan Molic
@@ -20,58 +15,86 @@ authors:
20
15
  autorequire:
21
16
  bindir: bin
22
17
  cert_chain: []
23
-
24
- date: 2011-01-19 00:00:00 -05:00
25
- default_executable:
26
- dependencies:
27
- - !ruby/object:Gem::Dependency
28
- name: syckle
18
+ date: 2011-11-11 00:00:00.000000000 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: blankslate
22
+ requirement: &26633440 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ type: :runtime
29
29
  prerelease: false
30
- requirement: &id001 !ruby/object:Gem::Requirement
30
+ version_requirements: *26633440
31
+ - !ruby/object:Gem::Dependency
32
+ name: detroit
33
+ requirement: &26632080 !ruby/object:Gem::Requirement
31
34
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- hash: 3
36
- segments:
37
- - 0
38
- version: "0"
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
39
  type: :development
40
- version_requirements: *id001
41
- - !ruby/object:Gem::Dependency
40
+ prerelease: false
41
+ version_requirements: *26632080
42
+ - !ruby/object:Gem::Dependency
42
43
  name: qed
44
+ requirement: &26631260 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
43
51
  prerelease: false
44
- requirement: &id002 !ruby/object:Gem::Requirement
52
+ version_requirements: *26631260
53
+ - !ruby/object:Gem::Dependency
54
+ name: lemon
55
+ requirement: &26630620 !ruby/object:Gem::Requirement
45
56
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
53
61
  type: :development
54
- version_requirements: *id002
55
- description: The Hashery is a collection of Hash-like classes, spun-off from the original Ruby Facets library. Included are the widely used OrderedHash, the related but more featured Dictionary class, a number of open classes, similiar to the standard OpenStruct and a few variations on the standard Hash.
56
- email: transfire@gmail.com
57
- executables: []
62
+ prerelease: false
63
+ version_requirements: *26630620
64
+ description: ! 'The Hashery is a collection of Hash-like classes, spun-off from the
65
+ original
58
66
 
59
- extensions: []
67
+ Ruby Facets library. Included are the widely used OrderedHash, the related but
68
+
69
+ more featured Dictionary class, a number of open classes, similiar to the
60
70
 
61
- extra_rdoc_files:
71
+ standard OpenStruct and a few variations on the standard Hash.'
72
+ email:
73
+ - transfire@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files:
77
+ - HISTORY.rdoc
62
78
  - README.rdoc
63
- files:
79
+ - QED.rdoc
80
+ - COPYING.rdoc
81
+ files:
64
82
  - .ruby
83
+ - .yardopts
65
84
  - lib/hashery/association.rb
85
+ - lib/hashery/basic_object.rb
66
86
  - lib/hashery/basic_struct.rb
67
87
  - lib/hashery/basicobject.rb
68
88
  - lib/hashery/basicstruct.rb
69
89
  - lib/hashery/casting_hash.rb
70
90
  - lib/hashery/castinghash.rb
91
+ - lib/hashery/core_ext.rb
71
92
  - lib/hashery/dictionary.rb
72
93
  - lib/hashery/fuzzy_hash.rb
73
94
  - lib/hashery/fuzzyhash.rb
74
95
  - lib/hashery/ini.rb
96
+ - lib/hashery/key_hash.rb
97
+ - lib/hashery/keyhash.rb
75
98
  - lib/hashery/linked_list.rb
76
99
  - lib/hashery/linkedlist.rb
77
100
  - lib/hashery/lru_hash.rb
@@ -90,8 +113,6 @@ files:
90
113
  - lib/hashery/propertyhash.rb
91
114
  - lib/hashery/query_hash.rb
92
115
  - lib/hashery/queryhash.rb
93
- - lib/hashery/sparse_array.rb
94
- - lib/hashery/sparsearray.rb
95
116
  - lib/hashery/stash.rb
96
117
  - lib/hashery/static_hash.rb
97
118
  - lib/hashery/statichash.rb
@@ -108,52 +129,38 @@ files:
108
129
  - qed/09_ostructable.rdoc
109
130
  - qed/applique/ae.rb
110
131
  - test/case_association.rb
132
+ - test/case_basicstruct.rb
111
133
  - test/case_dictionary.rb
134
+ - test/case_keyhash.rb
112
135
  - test/case_opencascade.rb
113
136
  - test/case_openhash.rb
114
- - test/case_openobject.rb
115
- - test/case_sparsearray.rb
116
- - test/case_stash.rb
117
137
  - HISTORY.rdoc
118
- - LICENSE
119
138
  - README.rdoc
120
- - NOTICE
121
- has_rdoc: true
139
+ - QED.rdoc
140
+ - COPYING.rdoc
122
141
  homepage: http://rubyworks.github.com/hashery
123
- licenses:
124
- - Apache 2.0
142
+ licenses:
143
+ - BSD-2-Clause
125
144
  post_install_message:
126
- rdoc_options:
127
- - --title
128
- - Hashery API
129
- - --main
130
- - README.rdoc
131
- require_paths:
145
+ rdoc_options: []
146
+ require_paths:
132
147
  - lib
133
- required_ruby_version: !ruby/object:Gem::Requirement
148
+ required_ruby_version: !ruby/object:Gem::Requirement
134
149
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- hash: 3
139
- segments:
140
- - 0
141
- version: "0"
142
- required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
155
  none: false
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 0
150
- version: "0"
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
151
160
  requirements: []
152
-
153
- rubyforge_project: hashery
154
- rubygems_version: 1.3.7
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.10
155
163
  signing_key:
156
164
  specification_version: 3
157
165
  summary: Facets-bread collection of Hash-like classes.
158
166
  test_files: []
159
-