Class: Tally::RecordSearcher

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ RecordSearcher

Returns a new instance of RecordSearcher.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tally/record_searcher.rb', line 6

def initialize(params = {})
  @params = params || {}

  if ActionController::Parameters === params
    if params.permitted?
      @params = params.to_h
    else
      @params = {}
    end
  end

  @params = @params.symbolize_keys
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/tally/record_searcher.rb', line 4

def params
  @params
end

Class Method Details

.search(params = {}) ⇒ Object



32
33
34
# File 'lib/tally/record_searcher.rb', line 32

def self.search(params = {})
  new(params).records
end

Instance Method Details

#daysObject



20
21
22
# File 'lib/tally/record_searcher.rb', line 20

def days
  @keys ||= build_search_scope.select(:day).distinct.reorder(day: :desc)
end

#keysObject



24
25
26
# File 'lib/tally/record_searcher.rb', line 24

def keys
  @keys ||= build_search_scope.select(:key).distinct.reorder(:key)
end

#recordsObject



28
29
30
# File 'lib/tally/record_searcher.rb', line 28

def records
  @records ||= build_search_scope
end