Class: Prosperity::Aggregate::AggregateBuilder
- Inherits:
-
Object
- Object
- Prosperity::Aggregate::AggregateBuilder
- Defined in:
- lib/prosperity/aggregate/aggregate_builder.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #average(column) ⇒ Object
- #build ⇒ Object
- #count ⇒ Object
-
#initialize(string = nil, &block) ⇒ AggregateBuilder
constructor
A new instance of AggregateBuilder.
- #maximum(column) ⇒ Object
- #minimum(column) ⇒ Object
- #sum(column) ⇒ Object
Constructor Details
#initialize(string = nil, &block) ⇒ AggregateBuilder
Returns a new instance of AggregateBuilder.
5 6 7 8 9 10 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 5 def initialize(string = nil, &block) raise "Can't specify a string and a block" if string && block_given? @string = string @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 3 def block @block end |
Instance Method Details
#average(column) ⇒ Object
37 38 39 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 37 def average(column) Aggregate::Average.new(column) end |
#build ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 12 def build res = @string ? @string : instance_eval(&block) if res.is_a?(String) Aggregate::Sql.new(res) else res end end |
#count ⇒ Object
21 22 23 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 21 def count Aggregate::Count.new end |
#maximum(column) ⇒ Object
29 30 31 |
# File 'lib/prosperity/aggregate/aggregate_builder.rb', line 29 def maximum(column) Aggregate::Maximum.new(column) end |