josh-multimap 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -145,20 +145,6 @@ class NestedMultimap < Multimap
145
145
  containers
146
146
  end
147
147
 
148
- # call-seq:
149
- # multimap.height => fixnum
150
- #
151
- # Returns the deepest level of nesting.
152
- #
153
- # map = NestedMultimap["a" => 100, "b" => 200]
154
- # map["a", "b"] = 101
155
- # map.height #=> 2
156
- # map["a", "b", "c"] = 102
157
- # map.height #=> 3
158
- def height
159
- containers_with_default.max { |a, b| a.length <=> b.length }.length
160
- end
161
-
162
148
  def inspect #:nodoc:
163
149
  super.gsub(/\}$/, ", default => #{default.inspect}}")
164
150
  end
metadata CHANGED
@@ -1,20 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: josh-multimap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
8
- - Joshua Hull
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-05-26 00:00:00 -07:00
12
+ date: 2009-07-26 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies: []
16
15
 
17
- description: Multimap includes a standard Ruby multimap implementation as well as a nested multimap and a fuzzy nested multimap
16
+ description: Multimap includes a Ruby multimap implementation
18
17
  email: josh@joshpeek.com
19
18
  executables: []
20
19
 
@@ -25,7 +24,6 @@ extra_rdoc_files:
25
24
  - MIT-LICENSE
26
25
  files:
27
26
  - ext/nested_multimap_ext.c
28
- - lib/fuzzy_nested_multimap.rb
29
27
  - lib/multimap.rb
30
28
  - lib/multiset.rb
31
29
  - lib/nested_multimap.rb
@@ -1,88 +0,0 @@
1
- require 'nested_multimap'
2
-
3
- # FuzzyNestedMultimap is an extension on top of NestedMultimap
4
- # that allows fuzzy matching.
5
- class FuzzyNestedMultimap < NestedMultimap
6
- def self.[](*args) #:nodoc:
7
- map = super
8
- map.instance_variable_set('@fuzz', {})
9
- map
10
- end
11
-
12
- def initialize(default = []) #:nodoc:
13
- @fuzz = {}
14
- super
15
- end
16
-
17
- def initialize_copy(original) #:nodoc:
18
- @fuzz = original.instance_variable_get('@fuzz').dup
19
- super
20
- end
21
-
22
- # call-seq:
23
- # multimap[*keys] = value => value
24
- # multimap.store(*keys, value) => value
25
- #
26
- # Associates the value given by <i>value</i> with multiple key
27
- # given by <i>keys</i>. Valid keys are restricted to strings
28
- # and regexps. If a Regexp is used as a key, the value will be
29
- # insert at every String key that matches that expression.
30
- def store(*args)
31
- keys = args.dup
32
- value = keys.pop
33
- key = keys.shift
34
-
35
- raise ArgumentError, 'wrong number of arguments (1 for 2)' unless value
36
-
37
- unless key.respond_to?(:=~)
38
- raise ArgumentError, "unsupported key: #{args.first.inspect}"
39
- end
40
-
41
- if key.is_a?(Regexp)
42
- @fuzz[value] = key
43
- if keys.empty?
44
- hash_each_pair { |k, l| l << value if k =~ key }
45
- self.default << value
46
- else
47
- hash_each_pair { |k, _|
48
- if k =~ key
49
- args[0] = k
50
- super(*args)
51
- end
52
- }
53
-
54
- self.default = self.class.new(default) unless default.is_a?(self.class)
55
- default[*keys.dup] = value
56
- end
57
- else
58
- super(*args)
59
- end
60
- end
61
- alias_method :[]=, :store
62
-
63
- def freeze #:nodoc:
64
- @fuzz.clear
65
- @fuzz = nil
66
- super
67
- end
68
-
69
- undef :index, :invert
70
-
71
- protected
72
- def update_container(key) #:nodoc:
73
- super do |container|
74
- if container.is_a?(self.class)
75
- container.each_container_with_default do |c|
76
- c.delete_if do |value|
77
- (requirement = @fuzz[value]) && key !~ requirement
78
- end
79
- end
80
- else
81
- container.delete_if do |value|
82
- (requirement = @fuzz[value]) && key !~ requirement
83
- end
84
- end
85
- yield container
86
- end
87
- end
88
- end