Class: Tricle::ActiveRecordMetric

Inherits:
Metric
  • Object
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?

Methods included from Aggregation

#periods_ago, #range_average, #range_values

Constructor Details

This class inherits a constructor from Tricle::Metric

Instance Method Details

#itemsObject



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_columnObject



9
10
11
# File 'lib/tricle/active_record_metric.rb', line 9

def time_column
  options[:time_column] || 'created_at'
end

#totalObject



25
26
27
# File 'lib/tricle/active_record_metric.rb', line 25

def total
  items.count
end

#unitObject



13
14
15
# File 'lib/tricle/active_record_metric.rb', line 13

def unit
  options[:unit] || 'record'
end