Sha256: b822303eb9f6e513dbda2f46e52938cfd1e5ac76d22ce286f77e9bc103722667

Contents?: true

Size: 767 Bytes

Versions: 28

Compression:

Stored size: 767 Bytes

Contents

module Praxis
  module Types

    class FuzzyHash
      def initialize(value={})
        @hash = {}
        @regexes = []
        update(value)
      end

      def update(value)
        value.each do |k,v|
          self[k] = v
        end

        self
      end

      def []=(k,v)
        case k
        when Regexp
          @regexes << k
        end
        @hash[k] = v
      end

      def [](k)
        return @hash[k] if @hash.key?(k)

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

        nil
      end

      def method_missing(*args, &block)
        @hash.send(*args, &block)
      end

      def respond_to_missing?(*args)
        @hash.respond_to?(*args)
      end

    end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.17 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.16 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.15 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.14 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.13 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.12 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.11 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.10 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.9 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.8 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.7 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.6 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.5 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.4 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.3 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.2 lib/praxis/types/fuzzy_hash.rb
praxis-2.0.pre.1 lib/praxis/types/fuzzy_hash.rb
praxis-0.22.pre.2 lib/praxis/types/fuzzy_hash.rb
praxis-0.22.pre.1 lib/praxis/types/fuzzy_hash.rb