Class: Mercy::Report::Range

Inherits:
ActiveRecord show all
Defined in:
lib/mercy/report/range.rb

Constant Summary collapse

ALLOWED_PARAMETERS =
[:period, :maximum, :minimum]
DEFAULT_OPTION =
{
  period: 1.day,
  scope: :all,
}

Instance Attribute Summary

Attributes inherited from Mercy::Report

#json

Instance Method Summary collapse

Methods inherited from Mercy::Report

#status

Constructor Details

#initialize(options) ⇒ Range

Returns a new instance of Range.



14
15
16
# File 'lib/mercy/report/range.rb', line 14

def initialize(options)
  super(DEFAULT_OPTION.merge(options))
end

Instance Method Details

#as_jsonObject



26
27
28
29
30
31
# File 'lib/mercy/report/range.rb', line 26

def as_json
  {
    status: status,
    count: count
  }
end

#countObject



33
34
35
# File 'lib/mercy/report/range.rb', line 33

def count
  scoped.count
end

#error?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/mercy/report/range.rb', line 22

def error?
  @error ||= !count_in_range?
end

#scopedObject



18
19
20
# File 'lib/mercy/report/range.rb', line 18

def scoped
  @scoped ||= fetch_scoped(last_entries, scope)
end