class Praxis::Types::FuzzyHash

Public Class Methods

new(value = {}) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 6
def initialize(value = {})
  @hash = {}
  @regexes = []
  update(value)
end

Public Instance Methods

[](key) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 28
def [](key)
  return @hash[key] if @hash.key?(key)

  key = key.to_s
  @regexes.each do |regex|
    return @hash[regex] if regex.match(key)
  end

  nil
end
[]=(key, val) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 20
def []=(key, val)
  case key
  when Regexp
    @regexes << key
  end
  @hash[key] = val
end
method_missing(*args, &block) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 39
def method_missing(*args, &block)
  @hash.send(*args, &block)
end
respond_to_missing?(*args) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 43
def respond_to_missing?(*args)
  @hash.respond_to?(*args)
end
update(value) click to toggle source
# File lib/praxis/types/fuzzy_hash.rb, line 12
def update(value)
  value.each do |key, val|
    self[key] = val
  end

  self
end