Class: TogglBillable::Formatter::Details
- Defined in:
- lib/toggl_billable/formatter/details.rb
Constant Summary collapse
- SKIP_GROUP_DATES =
[]
- SHORT_DATES =
[nil]
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#billable_items(with_dates = true) ⇒ Object
TODO: make this working also for different grouping than default.
Methods inherited from Base
Constructor Details
This class inherits a constructor from TogglBillable::Formatter::Base
Instance Method Details
#billable_items(with_dates = true) ⇒ Object
TODO: make this working also for different grouping than default
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/toggl_billable/formatter/details.rb', line 8 def billable_items(with_dates = true) group = data.group_by { |d| d['client'] } group.each do |group_name, group_items| key = group_name || @no_client_key billable[key] = [] unless billable[key] subgroup = group_items.group_by { |d| d['project'] } subgroup.each do |subgroup_name, subgroup_items| subgroup_items.group_by { |d| d['description'] }.each do |item, data| if with_dates && !SKIP_GROUP_DATES.include?(subgroup_name) task = "#{dates(data, SHORT_DATES.include?(subgroup_name))}: " else task = '' end if item && subgroup_name task += "#{subgroup_name}: #{item}" elsif item task += "#{item}" elsif subgroup_name task += "#{subgroup_name}" end billable[key] << { task: task, amount: data.map {|i| i['dur']}.reduce(0, :+).to_hours, unit: :hours } end end end billable end |