Class: SearchFlip::Result

Inherits:
Hash
  • Object
show all
Defined in:
lib/search_flip/result.rb

Overview

The SearchFlip::Result class is a simple Hash, but extended with method-like access. Keys assigned via methods are stored as strings.

Examples:

method access

result = SearchFlip::Result.new
result["some_key"] = "value"
result.some_key # => "value"

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



11
12
13
# File 'lib/search_flip/result.rb', line 11

def method_missing(name, *args, &block)
  self[name.to_s]
end

Class Method Details

.from_hit(hit) ⇒ Object



19
20
21
22
23
# File 'lib/search_flip/result.rb', line 19

def self.from_hit(hit)
  res = self[hit["_source"] || {}]
  res["_hit"] = self[hit].tap { |hash| hash.delete("_source") }
  res
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/search_flip/result.rb', line 15

def respond_to_missing?(name, include_private = false)
  key?(name.to_s) || super
end