Sha256: b71f7f4f97eed9c9d040168bbe29c0b4ddbdb94eb8e3eaf458181c8775f7a394

Contents?: true

Size: 797 Bytes

Versions: 11

Compression:

Stored size: 797 Bytes

Contents

module Waistband
  class Result

    def initialize(result_hash)
      @result_hash = result_hash
    end

    def to_hash
      @result_hash['_source']
    end

    def [](key)
      @result_hash['_source'][key.to_s]
    end

    def method_missing(method_name, *args, &block)
      return @result_hash[method_name.to_s] if @result_hash.keys.include?(method_name.to_s)
      return @result_hash['_source'][method_name.to_s] if @result_hash['_source'] && @result_hash['_source'].keys.include?(method_name.to_s)
      nil
    end

    def respond_to_missing?(method_name, include_private = false)
      return true if @result_hash.keys.include?(method_name.to_s)
      return true if @result_hash['_source'] && @result_hash['_source'].keys.include?(method_name.to_s)
      super
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
waistband-0.16.1 lib/waistband/result.rb
waistband-0.15.2 lib/waistband/result.rb
waistband-0.15.1 lib/waistband/result.rb
waistband-0.14.3 lib/waistband/result.rb
waistband-0.14.2 lib/waistband/result.rb
waistband-0.14.1 lib/waistband/result.rb
waistband-0.14.0 lib/waistband/result.rb
waistband-0.13.0 lib/waistband/result.rb
waistband-0.12.2 lib/waistband/result.rb
waistband-0.12.1 lib/waistband/result.rb
waistband-0.11.3 lib/waistband/result.rb