Class: Tricle::Metric

Inherits:
Object
  • Object
show all
Includes:
Aggregation
Defined in:
lib/tricle/metric.rb

Direct Known Subclasses

ActiveRecordMetric

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Aggregation

#periods_ago, #range_average, #range_values

Constructor Details

#initialize(opts = {}) ⇒ Metric

Returns a new instance of Metric.



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

def initialize(opts = {})
  @now = Tricle::Time.new(opts[:now])
  @options = opts
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



10
11
12
# File 'lib/tricle/metric.rb', line 10

def now
  @now
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/tricle/metric.rb', line 10

def options
  @options
end

Instance Method Details

#betterObject



29
30
31
# File 'lib/tricle/metric.rb', line 29

def better
  options[:better] || :higher
end

#items_for_range(start_at, end_at) ⇒ Object



41
42
43
# File 'lib/tricle/metric.rb', line 41

def items_for_range(start_at, end_at)
  raise Tricle::AbstractMethodError.new
end

#size_for_range(start_at, end_at) ⇒ Object



37
38
39
# File 'lib/tricle/metric.rb', line 37

def size_for_range(start_at, end_at)
  self.items_for_range(start_at, end_at).size
end

#sparkline?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/tricle/metric.rb', line 17

def sparkline?
  if options.key?(:sparkline)
    options[:sparkline]
  else
    Tricle.configuration.sparklines
  end
end

#titleObject



33
34
35
# File 'lib/tricle/metric.rb', line 33

def title
  options[:title] || self.class.name.titleize
end

#total?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/tricle/metric.rb', line 45

def total?
  self.respond_to?(:total)
end

#unitObject



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

def unit
  options[:unit]
end