class Identities

Public Class Methods

new(hash) click to toggle source
# File lib/passage/identities.rb, line 2
def initialize(hash)
  @regex = {}
  @hash = {}
  hash.keys.each do |k|
    if k.is_a? Regexp
      @regex[k] = hash[k]   
    else
      @hash[k] = hash[k]
    end
  end
end

Public Instance Methods

[](index) click to toggle source
# File lib/passage/identities.rb, line 14
def [](index)
  @hash[index] || regex_lookup(index)
end
count() click to toggle source
# File lib/passage/identities.rb, line 18
def count
  @hash.keys.count + @regex.keys.count
end

Private Instance Methods

regex_lookup(index) click to toggle source
# File lib/passage/identities.rb, line 22
def regex_lookup(index)
  @regex.keys.each do |k|
    if index =~ k
      subj = @regex[k]
      if(subj.respond_to? :merge)
        return subj.dup.merge(subj) { |k,v|  eval("\"#{v}\"") }
      elsif(subj.respond_to? :map)
        return subj.map { |e| eval("\"#{v}\"") }
      else
        return eval("\"#{v}\"")
      end
    end
  end
  nil
end