Class: Dalli::Ui::StatsPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/ui/stats_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dalli_stats, template) ⇒ StatsPresenter

Returns a new instance of StatsPresenter


9
10
11
12
# File 'lib/dalli/ui/stats_presenter.rb', line 9

def initialize(dalli_stats, template)
  @dalli = Hashie::Mash.new(dalli_stats)
  @template = template
end

Instance Attribute Details

#dalliObject

Returns the value of attribute dalli


7
8
9
# File 'lib/dalli/ui/stats_presenter.rb', line 7

def dalli
  @dalli
end

Instance Method Details

#cache_sizeObject


21
22
23
# File 'lib/dalli/ui/stats_presenter.rb', line 21

def cache_size
  h.number_to_human_size(dalli.limit_maxbytes)
end

#chart_dataObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dalli/ui/stats_presenter.rb', line 29

def chart_data
  [
    {
      value: 100 - hit_rate,
      count: dalli.get_misses,
      color: "#F7464A",
      highlight: "#FF5A5E",
      label: "Miss rate"
    },
    {
      value: hit_rate,
      count: dalli.get_hits,
      color: "#46BFBD",
      highlight: "#5AD3D1",
      label: "Hit rate"
    }
  ]
end

#hit_rateObject


14
15
16
17
18
19
# File 'lib/dalli/ui/stats_presenter.rb', line 14

def hit_rate
  hit_rate = 0
  total = Integer(dalli.get_hits) + Integer(dalli.get_misses)
  hit_rate = Integer(dalli.get_hits).to_f / total.to_f * 100 if total > 0
  hit_rate.round
end

#host_id(host) ⇒ Object


25
26
27
# File 'lib/dalli/ui/stats_presenter.rb', line 25

def host_id(host)
  Digest::SHA1.hexdigest host
end