Class: BBNW::LineItemUtils

Inherits:
Object
  • Object
show all
Extended by:
InvoiceDisplayUtils
Defined in:
lib/utils/line_item_utils.rb

Constant Summary collapse

MAX_IDLE =
900

Class Method Summary collapse

Methods included from InvoiceDisplayUtils

company, display_price, header, message_display

Methods included from DateTimeUtils

#is_number?, #long_date, #long_date_time, #long_time, #parse_time, #short_date, #short_time, #time_description

Class Method Details

.billed_seconds(activities) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/utils/line_item_utils.rb', line 29

def self.billed_seconds(activities)
  seconds = 0
  activities.each do |activity|
    time_elapsed = activity.total_seconds
    time_elapsed = MAX_IDLE if time_elapsed > MAX_IDLE
    seconds += time_elapsed
  end
  seconds
end

.group_line_items(line_items, prev_line_items = {}, group_by_task_id = true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/utils/line_item_utils.rb', line 9

def self.group_line_items(line_items, prev_line_items = {}, group_by_task_id = true)
  grouped_line_items = prev_line_items.clone

  line_items.each do |billed_commit, activities|

    # Let's look for a long numeric ID and group by that; if it doesn't exist
    #   Add the commit item as it's own line item (hence the random id).
    task_id = "== #{short_date(billed_commit.timestamp)} =="
    task_id = billed_commit.task_id if group_by_task_id

    billable_item = grouped_line_items.has_key?(task_id) ? grouped_line_items[task_id] : BBNW::Billable.new

    billable_item.total_time+=(activities.is_a?(Array) ? billed_seconds(activities) : activities)
    billable_item.descriptions << billed_commit.message
    grouped_line_items[task_id] = billable_item
  end

  grouped_line_items
end