Special type of Hash that uses Regexp keys and maintains insertion order. When searching for a string, the first match (of either kind) is used. Allows backreferences from the key match to be used in the value with $1..$n notation in val str.
Entries are kept in insertion order. Searches/insertion are slow, iteration is constant time. It‘s basically an unbucketed hash.
Create a new RxHash, copying the supplied map (in random order).
[ show source ]
# File lib/rote/rotetasks.rb, line 73
73: def initialize(map = nil)
74: @data = []
75: map.each { |k,v| self[k] = v } if map
76: end
Fetch the first matching data.
[ show source ]
# File lib/rote/rotetasks.rb, line 88
88: def [](key)
89: md = nil
90: if v = @data.detect { |it| md = /^#{it[0]}$/.match(key.to_s) }
91: v[1][0].gsub!(/\$(\d)/) { md[$1.to_i] }
92: v[1]
93: end
94: end
Insert the given regex key unless it already exists. You may use string representations for the keys, but they are converted as-is to regexps.
Returns the value that was inserted, or nil.
[ show source ]
# File lib/rote/rotetasks.rb, line 83
83: def []=(key,value)
84: @data << [key,value] unless member?(key)
85: end
Fetch a single entry based on key equality.
[ show source ]
# File lib/rote/rotetasks.rb, line 97
97: def fetch_entry(key)
98: @data.detect { |it| it[0] == key }
99: end
Determine membership based on key equality.
[ show source ]
# File lib/rote/rotetasks.rb, line 102
102: def member?(key)
103: true if fetch_entry(key)
104: end