Class: MovingWindow

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

Defined Under Namespace

Classes: Proc

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ MovingWindow

Returns a new instance of MovingWindow.



10
11
12
# File 'lib/moving_window.rb', line 10

def initialize(&block)
  @block = block
end

Class Method Details

.scope(column = :created_at, &block) ⇒ Object



3
4
5
6
7
8
# File 'lib/moving_window.rb', line 3

def self.scope(column = :created_at, &block)
  arel = block.binding.eval("self")
  instance = new(&block)

  Proc.new(instance, arel, column)
end

Instance Method Details

#filter(scope, params = {}) ⇒ Object



14
15
16
17
18
# File 'lib/moving_window.rb', line 14

def filter(scope, params = {})
  column, qualifier = parse(params)
  t = scope.table_name
  scope.where(["#{t}.#{column} #{qualifier} ? and ?", *timestamps])
end