Class: Timely::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/timely/row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  options.reverse_merge! default_options.reverse_merge(cacheable: true)

  self.title    = title
  self.key      = key
  self.scope    = scope
  self.options  = options
end

Instance Attribute Details

#keyObject

Instance Definition ##



11
12
13
# File 'lib/timely/row.rb', line 11

def key
  @key
end

#optionsObject

Instance Definition ##



11
12
13
# File 'lib/timely/row.rb', line 11

def options
  @options
end

#scopeObject

Instance Definition ##



11
12
13
# File 'lib/timely/row.rb', line 11

def scope
  @scope
end

#titleObject

Instance Definition ##



11
12
13
# File 'lib/timely/row.rb', line 11

def title
  @title
end

Instance Method Details

#cache_keyObject



38
39
40
# File 'lib/timely/row.rb', line 38

def cache_key
  title.parameterize
end

#cacheable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/timely/row.rb', line 42

def cacheable?
  !!options[:cacheable]
end

#default_optionsObject

Defaults ##



6
# File 'lib/timely/row.rb', line 6

class_attribute :default_options, instance_writer: false

#to_sObject



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