Class: Waistband::Result

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

Instance Method Summary collapse

Constructor Details

#initialize(result_hash) ⇒ Result

Returns a new instance of Result.



4
5
6
# File 'lib/waistband/result.rb', line 4

def initialize(result_hash)
  @result_hash = result_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



16
17
18
19
20
# File 'lib/waistband/result.rb', line 16

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

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/waistband/result.rb', line 12

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

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

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/waistband/result.rb', line 22

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

#to_hashObject



8
9
10
# File 'lib/waistband/result.rb', line 8

def to_hash
  @result_hash['_source']
end