Class: Dude::Toggl::IssueSpendTime
- Inherits:
-
Base
- Object
- Base
- Dude::Toggl::IssueSpendTime
show all
- Defined in:
- lib/dude/toggl/issue_spend_time.rb
Constant Summary
Constants included
from Settings
Settings::CONFIG_FILE
Instance Attribute Summary
Attributes included from Service
#options
Instance Method Summary
collapse
Methods inherited from Base
#projects_response, #toggl_api, #toggl_report
Methods included from Settings
#file, #read, #settings
Methods included from Service
included, #initialize
Instance Method Details
#call ⇒ Object
4
5
6
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 4
def call
parse_time_entries_list
end
|
#current_issue_time_entries ⇒ Object
24
25
26
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 24
def current_issue_time_entries
time_entries.select { |entry| match_project_id?(entry) && match_issue_id?(entry) }
end
|
38
39
40
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 38
def formatted_time_entries
current_issue_time_entries.map {|a| [a['description'], a['duration']]}
end
|
#match_issue_id?(time_entry) ⇒ Boolean
32
33
34
35
36
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 32
def match_issue_id?(time_entry)
time_entry['description'].match?(/\(##{options[:issue_id]}\)/) ||
time_entry['description'].match?(/##{options[:issue_id]}\s/)
end
|
#match_project_id?(time_entry) ⇒ Boolean
28
29
30
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 28
def match_project_id?(time_entry)
time_entry['pid'].eql? project_id
end
|
#params ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 8
def params
{
workspace_id: settings['TOGGL_WORKSPACE_ID'],
user_agent: settings['TOGGL_EMAIL'],
start_date: '2013-03-10T15:42:46+02:00'
}
end
|
#parse_time_entries_list ⇒ Object
42
43
44
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 42
def parse_time_entries_list
current_issue_time_entries.map {|a| a['duration'] }.sum
end
|
#project_id ⇒ Object
46
47
48
49
50
51
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 46
def project_id
@project_id ||= projects_array.find do |title, id|
title.eql?(options[:project_title])
end.last
end
|
#projects_array ⇒ Object
53
54
55
56
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 53
def projects_array
JSON.parse(projects_response)
.map { |a| [a['name'].downcase.gsub(/\s/, '-'), a['id']] }
end
|
#response ⇒ Object
16
17
18
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 16
def response
toggl_api['time_entries'].get params
end
|
#time_entries ⇒ Object
20
21
22
|
# File 'lib/dude/toggl/issue_spend_time.rb', line 20
def time_entries
JSON.parse(response.body)
end
|