Class: Tricle::ActiveRecordMetric
- Inherits:
-
Metric
- Object
- Metric
- Tricle::ActiveRecordMetric
show all
- Defined in:
- lib/tricle/active_record_metric.rb
Instance Attribute Summary
Attributes inherited from Metric
#now, #options
Instance Method Summary
collapse
Methods inherited from Metric
#better, #initialize, #sparkline?, #title, #total?
#periods_ago, #range_average, #range_values
Constructor Details
This class inherits a constructor from Tricle::Metric
Instance Method Details
#items ⇒ Object
5
6
7
|
# File 'lib/tricle/active_record_metric.rb', line 5
def items
options[:items] || raise(Tricle::AbstractMethodError.new)
end
|
#items_for_range(start_at, end_at) ⇒ Object
21
22
23
|
# File 'lib/tricle/active_record_metric.rb', line 21
def items_for_range(start_at, end_at)
items.where("#{time_column}" => start_at..end_at)
end
|
#size_for_range(start_at, end_at) ⇒ Object
17
18
19
|
# File 'lib/tricle/active_record_metric.rb', line 17
def size_for_range(start_at, end_at)
items.where("#{time_column}" => start_at..end_at).count
end
|
#time_column ⇒ Object
9
10
11
|
# File 'lib/tricle/active_record_metric.rb', line 9
def time_column
options[:time_column] || 'created_at'
end
|
#total ⇒ Object
25
26
27
|
# File 'lib/tricle/active_record_metric.rb', line 25
def total
items.count
end
|
#unit ⇒ Object
13
14
15
|
# File 'lib/tricle/active_record_metric.rb', line 13
def unit
options[:unit] || 'record'
end
|