Class: Timely::Column
- Inherits:
-
Object
- Object
- Timely::Column
- Defined in:
- lib/timely/column.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#period ⇒ Object
Returns the value of attribute period.
-
#starts_at ⇒ Object
Returns the value of attribute starts_at.
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#cacheable? ⇒ Boolean
only cache values when the period is over.
-
#ends_at ⇒ Object
calculate the end time.
-
#initialize(period, starts_at, options = {}) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
-
#midpoint ⇒ Object
calculate the time between the start and the end.
- #title ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(period, starts_at, options = {}) ⇒ Column
Returns a new instance of Column.
6 7 8 9 10 |
# File 'lib/timely/column.rb', line 6 def initialize(period, starts_at, ={}) self.period = period self.starts_at = starts_at self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/timely/column.rb', line 4 def @options end |
#period ⇒ Object
Returns the value of attribute period.
4 5 6 |
# File 'lib/timely/column.rb', line 4 def period @period end |
#starts_at ⇒ Object
Returns the value of attribute starts_at.
4 5 6 |
# File 'lib/timely/column.rb', line 4 def starts_at @starts_at end |
Instance Method Details
#cache_key ⇒ Object
42 43 44 |
# File 'lib/timely/column.rb', line 42 def cache_key [starts_at.to_i, ends_at.to_i].join(Timely.cache_separator) end |
#cacheable? ⇒ Boolean
only cache values when the period is over
47 48 49 |
# File 'lib/timely/column.rb', line 47 def cacheable? ends_at < Time.zone.now end |
#ends_at ⇒ Object
calculate the end time
17 18 19 20 21 22 |
# File 'lib/timely/column.rb', line 17 def ends_at @ends_at ||= begin args = period == :quarter ? { months: 3 } : { periods => 1 } starts_at.advance args end end |
#inspect ⇒ Object
12 13 14 |
# File 'lib/timely/column.rb', line 12 def inspect "#<#{self.class.name} period: #{period}, starts_at: #{starts_at}, ends_at: #{ends_at}>" end |
#midpoint ⇒ Object
calculate the time between the start and the end. useful as the x value for bar and line graphs
26 27 28 |
# File 'lib/timely/column.rb', line 26 def midpoint @midpoint ||= Time.at((starts_at.to_i + ends_at.to_i) / 2) end |
#title ⇒ Object
30 31 32 |
# File 'lib/timely/column.rb', line 30 def title format_time_for_human end |
#to_i ⇒ Object
38 39 40 |
# File 'lib/timely/column.rb', line 38 def to_i starts_at.to_i end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/timely/column.rb', line 34 def to_s format_time_for_group end |