Module: Freshtrack::TimeCollector::PunchyTemplate

Included in:
OneInchPunch, Punch
Defined in:
lib/freshtrack/time_collectors/punchy_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/freshtrack/time_collectors/punchy_template.rb', line 4

def options
  @options
end

Instance Method Details

#condense_time_data(time_data) ⇒ Object



10
11
12
13
# File 'lib/freshtrack/time_collectors/punchy_template.rb', line 10

def condense_time_data(time_data)
  date_data = times_to_dates(time_data)
  group_date_data(date_data)
end

#group_date_data(date_data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/freshtrack/time_collectors/punchy_template.rb', line 28

def group_date_data(date_data)
  separator = '-' * 20
  grouped = date_data.group_by { |x|  x['date'] }
  grouped.sort.inject([]) do |arr, (date, data)|
    this_date = { 'date' => date }
    this_date['hours'] = data.inject(0) { |sum, x|  sum + x['hours'] }
    this_date['hours'] = ('%.2f' % this_date['hours']).to_f
    this_date['notes'] = data.collect { |x|  x['log'].join("\n") }.join("\n" + separator + "\n")
    arr + [this_date]
  end
end

#initialize(options = {}) ⇒ Object



6
7
8
# File 'lib/freshtrack/time_collectors/punchy_template.rb', line 6

def initialize(options = {})
  @options = options
end

#times_to_dates(time_data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/freshtrack/time_collectors/punchy_template.rb', line 15

def times_to_dates(time_data)
  time_data.collect do |td|
    punch_in  = td.delete('in')
    punch_out = td.delete('out')

    if punch_out
      td['date']  = punch_in.to_date
      td['hours'] = (punch_out - punch_in).secs_to_hours
      td
    end
  end.compact
end