Class: Timely::Row
- Inherits:
-
Object
- Object
- Timely::Row
- Defined in:
- lib/timely/row.rb
Direct Known Subclasses
Timely::Rows::Average, Timely::Rows::AverageDaysBetween, Timely::Rows::AverageHoursBetween, Timely::Rows::AverageWeekHoursBetween, Timely::Rows::Count, Timely::Rows::Present, Timely::Rows::StandardDeviation, Timely::Rows::Sum, Timely::Rows::TotalCount, Timely::Rows::TotalSum
Instance Attribute Summary collapse
-
#key ⇒ Object
Instance Definition ##.
-
#options ⇒ Object
Instance Definition ##.
-
#scope ⇒ Object
Instance Definition ##.
-
#title ⇒ Object
Instance Definition ##.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #cacheable? ⇒ Boolean
-
#default_options ⇒ Object
Defaults ##.
-
#initialize(title, key, scope, options = {}) ⇒ Row
constructor
Title: string or symbol for I18n lookup Key: timestamp column name Scope: (internal) Generated by the report Options: cacheable: if true, cache past values in Redis transform: proc to apply to each value (e.g. for rounding), or pass ‘:round` to apply default rounding (two-decimal precision) or `:to_i` to round to 0 decimals.
- #to_s ⇒ Object
- #total(ends_at) ⇒ Object
-
#value(starts_at, ends_at) ⇒ Object
override value or raw_value in subclasses.
Constructor Details
#initialize(title, key, scope, options = {}) ⇒ Row
Title: string or symbol for I18n lookup Key: timestamp column name Scope: (internal) Generated by the report Options:
cacheable: if true, cache past values in Redis
transform: proc to apply to each value (e.g. for rounding), or pass
`:round` to apply default rounding (two-decimal precision) or `:to_i`
to round to 0 decimals
21 22 23 24 25 26 27 28 |
# File 'lib/timely/row.rb', line 21 def initialize(title, key, scope, ={}) .reverse_merge! .reverse_merge(cacheable: true) self.title = title self.key = key self.scope = scope self. = end |
Instance Attribute Details
#key ⇒ Object
Instance Definition ##
11 12 13 |
# File 'lib/timely/row.rb', line 11 def key @key end |
#options ⇒ Object
Instance Definition ##
11 12 13 |
# File 'lib/timely/row.rb', line 11 def @options end |
#scope ⇒ Object
Instance Definition ##
11 12 13 |
# File 'lib/timely/row.rb', line 11 def scope @scope end |
#title ⇒ Object
Instance Definition ##
11 12 13 |
# File 'lib/timely/row.rb', line 11 def title @title end |
Instance Method Details
#cache_key ⇒ Object
38 39 40 |
# File 'lib/timely/row.rb', line 38 def cache_key title.parameterize end |
#cacheable? ⇒ Boolean
42 43 44 |
# File 'lib/timely/row.rb', line 42 def cacheable? !![:cacheable] end |
#default_options ⇒ Object
Defaults ##
6 |
# File 'lib/timely/row.rb', line 6 class_attribute :default_options, instance_writer: false |
#to_s ⇒ Object
30 31 32 |
# File 'lib/timely/row.rb', line 30 def to_s "#<#{self.class.name} title: \"#{title}\", key: #{key}>" end |
#total(ends_at) ⇒ Object
53 54 55 |
# File 'lib/timely/row.rb', line 53 def total(ends_at) transform raw_value_from date_range_scope(nil, ends_at) end |
#value(starts_at, ends_at) ⇒ Object
override value or raw_value in subclasses
49 50 51 |
# File 'lib/timely/row.rb', line 49 def value(starts_at, ends_at) transform raw_value_from date_range_scope(starts_at, ends_at) end |