Class: Totalizer::Metric
- Inherits:
-
Object
- Object
- Totalizer::Metric
- Defined in:
- lib/totalizer/metric.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#map ⇒ Object
Returns the value of attribute map.
-
#model ⇒ Object
Returns the value of attribute model.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #attributes ⇒ Object
- #end_date ⇒ Object
- #finish ⇒ Object
- #finish_ids ⇒ Object
-
#initialize(params) ⇒ Metric
constructor
A new instance of Metric.
- #rate ⇒ Object
- #start ⇒ Object
- #start_date ⇒ Object
- #start_ids ⇒ Object
Constructor Details
#initialize(params) ⇒ Metric
Returns a new instance of Metric.
5 6 7 8 9 10 11 12 |
# File 'lib/totalizer/metric.rb', line 5 def initialize params self.model = params[:model] self.date = params[:date] || DateTime.now.change(hour: 0) self.duration = params[:duration] || 7 self.filter = params[:filter] self.map = params[:map] || 'id' validate_attributes! end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def date @date end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def duration @duration end |
#filter ⇒ Object
Returns the value of attribute filter.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def filter @filter end |
#ids ⇒ Object
Returns the value of attribute ids.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def ids @ids end |
#map ⇒ Object
Returns the value of attribute map.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def map @map end |
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def model @model end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/totalizer/metric.rb', line 3 def value @value end |
Instance Method Details
#attributes ⇒ Object
14 15 16 |
# File 'lib/totalizer/metric.rb', line 14 def attributes { model: model, date: date, duration: duration, filter: filter, map: map } end |
#end_date ⇒ Object
18 19 20 |
# File 'lib/totalizer/metric.rb', line 18 def end_date date end |
#finish ⇒ Object
46 47 48 |
# File 'lib/totalizer/metric.rb', line 46 def finish finish_ids.size end |
#finish_ids ⇒ Object
42 43 44 |
# File 'lib/totalizer/metric.rb', line 42 def finish_ids @finish_ids ||= calculate(["created_at < ?", end_date]) end |
#rate ⇒ Object
50 51 52 |
# File 'lib/totalizer/metric.rb', line 50 def rate start == 0 ? 0 : (finish - start).to_f / start.to_f end |
#start ⇒ Object
38 39 40 |
# File 'lib/totalizer/metric.rb', line 38 def start start_ids.size end |
#start_date ⇒ Object
22 23 24 |
# File 'lib/totalizer/metric.rb', line 22 def start_date date - duration.days end |
#start_ids ⇒ Object
34 35 36 |
# File 'lib/totalizer/metric.rb', line 34 def start_ids @start_ids ||= calculate(["created_at < ?", start_date]) end |