Class: Druid::PostAggregationOperation
- Inherits:
-
Object
- Object
- Druid::PostAggregationOperation
- Includes:
- PostAggregationOperators
- Defined in:
- lib/druid/post_aggregation.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #as(field) ⇒ Object
- #as_json(*a) ⇒ Object
- #get_field_names ⇒ Object
-
#initialize(left, operator, right) ⇒ PostAggregationOperation
constructor
A new instance of PostAggregationOperation.
- #to_hash ⇒ Object
- #to_json(*a) ⇒ Object
Methods included from PostAggregationOperators
Constructor Details
#initialize(left, operator, right) ⇒ PostAggregationOperation
Returns a new instance of PostAggregationOperation.
33 34 35 36 37 |
# File 'lib/druid/post_aggregation.rb', line 33 def initialize(left, operator, right) @left = left.is_a?(Numeric) ? PostAggregationConstant.new(left) : left @operator = operator @right = right.is_a?(Numeric) ? PostAggregationConstant.new(right) : right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
31 32 33 |
# File 'lib/druid/post_aggregation.rb', line 31 def left @left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/druid/post_aggregation.rb', line 31 def name @name end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
31 32 33 |
# File 'lib/druid/post_aggregation.rb', line 31 def operator @operator end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
31 32 33 |
# File 'lib/druid/post_aggregation.rb', line 31 def right @right end |
Instance Method Details
#as(field) ⇒ Object
39 40 41 42 |
# File 'lib/druid/post_aggregation.rb', line 39 def as(field) @name = field.name.to_s self end |
#as_json(*a) ⇒ Object
61 62 63 |
# File 'lib/druid/post_aggregation.rb', line 61 def as_json(*a) to_hash end |
#get_field_names ⇒ Object
44 45 46 47 48 49 |
# File 'lib/druid/post_aggregation.rb', line 44 def get_field_names field_names = [] field_names << left.get_field_names if left.respond_to?(:get_field_names) field_names << right.get_field_names if right.respond_to?(:get_field_names) field_names end |
#to_hash ⇒ Object
51 52 53 54 55 |
# File 'lib/druid/post_aggregation.rb', line 51 def to_hash hash = { "type" => "arithmetic", "fn" => @operator, "fields" => [@left.to_hash, @right.to_hash] } hash["name"] = @name if @name hash end |
#to_json(*a) ⇒ Object
57 58 59 |
# File 'lib/druid/post_aggregation.rb', line 57 def to_json(*a) to_hash.to_json(*a) end |