Class: ActiveMedian::SQLiteHandler
- Inherits:
-
Object
- Object
- ActiveMedian::SQLiteHandler
- Defined in:
- lib/active_median/sqlite_handler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #finalize(ctx) ⇒ Object
-
#initialize ⇒ SQLiteHandler
constructor
A new instance of SQLiteHandler.
-
#step(ctx, value, percentile) ⇒ Object
skip checks for 1.
Constructor Details
#initialize ⇒ SQLiteHandler
Returns a new instance of SQLiteHandler.
11 12 13 14 |
# File 'lib/active_median/sqlite_handler.rb', line 11 def initialize @values = [] @percentile = nil end |
Class Method Details
.arity ⇒ Object
3 4 5 |
# File 'lib/active_median/sqlite_handler.rb', line 3 def self.arity 2 end |
.name ⇒ Object
7 8 9 |
# File 'lib/active_median/sqlite_handler.rb', line 7 def self.name "percentile" end |
Instance Method Details
#finalize(ctx) ⇒ Object
27 28 29 30 31 |
# File 'lib/active_median/sqlite_handler.rb', line 27 def finalize(ctx) if @values.any? ctx.result = @values.percentile(@percentile / 100.0) end end |
#step(ctx, value, percentile) ⇒ Object
skip checks for
-
percentile between 0 and 100
-
percentile same for all rows
since input is already checked
20 21 22 23 24 25 |
# File 'lib/active_median/sqlite_handler.rb', line 20 def step(ctx, value, percentile) return if value.nil? raise ActiveRecord::StatementInvalid, "1st argument to percentile() is not numeric" unless value.is_a?(Numeric) @percentile ||= percentile @values << value end |