class Rote::ExtHash
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.
Public Class Methods
new(map = nil)
click to toggle source
Create a new RxHash, copying the supplied map (in random order).
# File lib/rote/rotetasks.rb 73 def initialize(map = nil) 74 @data = [] 75 map.each { |k,v| self[k] = v } if map 76 end
Public Instance Methods
[](key)
click to toggle source
Fetch the first matching data.
# File lib/rote/rotetasks.rb 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
[]=(key,value)
click to toggle source
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.
# File lib/rote/rotetasks.rb 83 def []=(key,value) 84 @data << [key,value] unless member?(key) 85 end
fetch_entry(key)
click to toggle source
Fetch a single entry based on key equality.
# File lib/rote/rotetasks.rb 97 def fetch_entry(key) 98 @data.detect { |it| it[0] == key } 99 end
member?(key)
click to toggle source
Determine membership based on key equality.
# File lib/rote/rotetasks.rb 102 def member?(key) 103 true if fetch_entry(key) 104 end