Class: Noiseless::Response::Aggregations

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/noiseless/response/aggregations.rb

Instance Method Summary collapse

Constructor Details

#initialize(aggs_hash) ⇒ Aggregations

Returns a new instance of Aggregations.



8
9
10
# File 'lib/noiseless/response/aggregations.rb', line 8

def initialize(aggs_hash)
  @aggs_hash = aggs_hash || {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Handle method conflicts with Enumerable methods



33
34
35
36
37
38
39
# File 'lib/noiseless/response/aggregations.rb', line 33

def method_missing(method_name, *args, &)
  if @aggs_hash.key?(method_name.to_s)
    @aggs_hash[method_name.to_s]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/noiseless/response/aggregations.rb', line 12

def [](key)
  @aggs_hash[key.to_s]
end

#eachObject



18
19
20
21
22
# File 'lib/noiseless/response/aggregations.rb', line 18

def each(&)
  return enum_for(__method__) unless block_given?

  @aggs_hash.each(&)
end

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

Returns:

  • (Boolean)


41
42
43
# File 'lib/noiseless/response/aggregations.rb', line 41

def respond_to_missing?(method_name, include_private = false)
  @aggs_hash.key?(method_name.to_s) || super
end

#to_hObject



28
29
30
# File 'lib/noiseless/response/aggregations.rb', line 28

def to_h
  @aggs_hash
end