Class: TogglBillable::Reports::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/toggl_billable/reports/base.rb

Direct Known Subclasses

Details, Summary

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
# File 'lib/toggl_billable/reports/base.rb', line 6

def initialize(options = {})
  @params = {
    workspace_id: options[:workspace_id] || User.new.default_workspace_id,
    user_agent: options[:user_agent] || 'toggl_client'
  }
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/toggl_billable/reports/base.rb', line 4

def options
  @options
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/toggl_billable/reports/base.rb', line 4

def params
  @params
end

#reportObject

Returns the value of attribute report.



4
5
6
# File 'lib/toggl_billable/reports/base.rb', line 4

def report
  @report
end

Instance Method Details

#billable_itemsObject



24
25
26
27
28
29
30
# File 'lib/toggl_billable/reports/base.rb', line 24

def billable_items
  params = {}
  params[:default_client] = options[:default_client] if options[:default_client]

  klass = Object.const_get("TogglBillable::Formatter::#{self.class.to_s.gsub(/^.*::/, '')}")
  klass.new(report, options).billable_items
end

#last_month_billableObject



14
15
16
17
18
19
20
21
22
# File 'lib/toggl_billable/reports/base.rb', line 14

def last_month_billable
  start = DateTime.now.prev_month

  start_date = start.strftime('%Y-%m-01')
  end_date   = DateTime.civil(start.year, start.month, -1).strftime(('%Y-%m-%d'))

  @report ||= get_report(start_date: start_date, end_date: end_date)
  billable_items
end