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)

20
21
22
23
# File 'lib/logstats/haml/helpers.rb', line 20

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

.productivity_tag(data) ⇒ Object

Outputs some basic productivity statistics


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/logstats/haml/helpers.rb', line 43

def self.productivity_tag(data)
  o=[]
  css_classes=[ 'productivity' ]

  if data[:total] > 0 then
    o << self.time_to_html(data[:total]) if data[:total] > 0
    percent=((data[:billable] / data[:total]) * 100).ceil
    o << "#{percent}% billable"
  end

  "<div class=\"#{css_classes.join(' ')}\">#{o.join(' | ')}</div>"
end

.remaining_tag(seconds_so_far, period) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/logstats/haml/helpers.rb', line 29

def self.remaining_tag(seconds_so_far, period)
  seconds=self.threshold_for_period(period) - seconds_so_far

  css_class=[ 'remaining ']
  if 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

.threshold_for_period(period) ⇒ Object

Returns the threshold number of seconds that need to be attained each period


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logstats/haml/helpers.rb', line 57

def self.threshold_for_period(period)
  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
end

.threshold_met?(seconds, period) ⇒ Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/logstats/haml/helpers.rb', line 25

def self.threshold_met?(seconds, period)
  (self.threshold_for_period(period) - seconds) < 0
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
14
15
16
# 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
  if o.size == 0 then
    o << "<span class=\"none\">NONE :(</span>"
  end
  o.join(' ')
end