Module: LogStats::Helpers

Defined in:
lib/logstats/haml/helpers.rb

Class Method Summary collapse

Class Method Details

.duration_tag(seconds, options = {}) ⇒ Object

Options:

:class : The CSS class to apply to the top element (default: duration)


17
18
19
20
# File 'lib/logstats/haml/helpers.rb', line 17

def self.duration_tag(seconds, options={})
  options[:class]='duration' if options[:class].nil?
  "<span class=\"#{options[:class]}\">#{self.time_to_html(seconds)}</span>"
end

.remaining_tag(seconds_so_far, period) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/logstats/haml/helpers.rb', line 22

def self.remaining_tag(seconds_so_far, period)
  seconds_required=case period
    when :day
      # 5 hrs per day
      5 * 3600
    when :week
      # 5 hrs per day, 5 days per week
      5 * 5 * 3600
    else
      raise "Unknown period: #{period}"
  end

  seconds=seconds_required - seconds_so_far

  css_class=[ 'remaining ']
  if seconds.nil? || seconds < 0 then
    content=self.time_to_html(seconds.abs) + ' over!'
    css_class << 'met'
  else
    content=self.time_to_html(seconds) + ' remaining'
  end
  "<div class=\"#{css_class.join(' ')}\">(#{content})</div>"
end

.time_to_html(seconds, options = {}) ⇒ Object

Turns a number of seconds into a pretty HTML string



6
7
8
9
10
11
12
13
# File 'lib/logstats/haml/helpers.rb', line 6

def self.time_to_html(seconds, options={})
  hrs=(seconds / 3600).floor
  min=(seconds % 3600).floor / 60
  o=[]
  o << "<span class=\"hour\">#{hrs}</span> hr" if hrs.to_i > 0
  o << "<span class=\"minute\">#{min}</span> min" if min.to_i > 0
  o.join(' ')
end