Class: Sinatra::MonittrHTML::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/monittr/sinatra/monittr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ HTML

Returns a new instance of HTML.



19
20
21
# File 'lib/monittr/sinatra/monittr.rb', line 19

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/monittr/sinatra/monittr.rb', line 17

def app
  @app
end

Instance Method Details

#clusterObject



23
24
25
# File 'lib/monittr/sinatra/monittr.rb', line 23

def cluster
  Monittr::Cluster.new(app.settings.monit_urls)
end

#htmlObject



27
28
29
# File 'lib/monittr/sinatra/monittr.rb', line 27

def html
  ERB.new( File.read( app.settings.template ) ).result(binding)
end

#stylesheetObject



31
32
33
# File 'lib/monittr/sinatra/monittr.rb', line 31

def stylesheet
  app.settings.stylesheet ? File.read( app.settings.stylesheet ) : ''
end

#time_in_words(seconds) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/monittr/sinatra/monittr.rb', line 35

def time_in_words(seconds)
  case seconds
  when 0..60
    "#{seconds        } seconds"
  when 60..3600
    value = seconds/60
    "#{value} minute#{value > 1 ? 's' : ''}"
  when 3600..86400
    value = seconds/3600
    "#{value} hour#{  value > 1 ? 's' : ''}"
  when 86400..604800
    value = seconds/86400
    "#{value} day#{   value > 1 ? 's' : ''}"
  when 604800..2419200
    value = seconds/604800
    "#{value} week#{  value > 1 ? 's' : ''}"
  else
    nil
  end
end