timetrello 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/time_trello/activity_record.rb +8 -5
- data/lib/time_trello/parser.rb +18 -18
- data/lib/time_trello/report.rb +17 -2
- data/lib/time_trello/trello_driver.rb +49 -6
- data/lib/time_trello/version.rb +1 -1
- data/lib/time_trello.rb +17 -3
- data/readme.md +104 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d38c4826f46020f4c8a0d0ab696dabd913bf2ad2
|
4
|
+
data.tar.gz: fefbbf22b394d766978f98b58e290e2490257754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2b5036e27edb486e40051aafb91266708f1aa67ce187f16d3ce953a33549a22e80d48f71474cdbce879673b29f8680d1dc7d65af6b1fad84c30c5bfd335ed5e
|
7
|
+
data.tar.gz: eb60c4efa997f3c1d47041554ce18b06a3d8a1fd86a046be0667c5a35bbbd372bbd2f17fd877821a6461b29037782f73daa22c92526b703ea2d7c31c1c9b2f67
|
@@ -17,6 +17,8 @@ module TimeTrello
|
|
17
17
|
class ActivityRecord
|
18
18
|
include Comparable
|
19
19
|
|
20
|
+
# Public: This activity id. This is, actually, Trello's Action Identification.
|
21
|
+
attr_accessor :id
|
20
22
|
# Public: Task duration
|
21
23
|
attr_accessor :duration
|
22
24
|
# Public: Task owner
|
@@ -36,11 +38,12 @@ module TimeTrello
|
|
36
38
|
# duration - The task duration
|
37
39
|
def initialize(*args)
|
38
40
|
if args.size != 0
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
41
|
+
@id = args[0]
|
42
|
+
@duration = args[1]
|
43
|
+
@owner = args[2]
|
44
|
+
@project = args[3]
|
45
|
+
@start_date = args[4]
|
46
|
+
@task_description = args[5]
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
data/lib/time_trello/parser.rb
CHANGED
@@ -15,12 +15,9 @@ module TimeTrello
|
|
15
15
|
# Public: Parser for Trello::Action to ActivityRecord conversion. See
|
16
16
|
# ruby-trello for Trello::Action class specification.
|
17
17
|
class Parser
|
18
|
-
# Private: Instance of Trello::Action to analize
|
19
|
-
private
|
20
|
-
attr :action_record
|
21
|
-
|
22
18
|
# Private: Prefix to use in detecting if a given comment is really an
|
23
19
|
# expected one
|
20
|
+
private
|
24
21
|
attr :prefix
|
25
22
|
|
26
23
|
# Private: Class variable used to hold the workflow pieces that parses the
|
@@ -47,21 +44,21 @@ module TimeTrello
|
|
47
44
|
txt_duration = action_record[:action].data['text'].scan(/[0-9]+:[0-9]+/)
|
48
45
|
activity.duration = Duration.new(txt_duration[0]) unless txt_duration.size == 0
|
49
46
|
|
50
|
-
activity.duration
|
47
|
+
!activity.duration.nil?
|
51
48
|
end,
|
52
49
|
|
53
50
|
# Parses the comment owner
|
54
51
|
lambda do |action_record, activity|
|
55
52
|
activity.owner = action_record[:member].full_name
|
56
53
|
|
57
|
-
activity.owner
|
54
|
+
!activity.owner.nil?
|
58
55
|
end,
|
59
56
|
|
60
57
|
# Parses the project
|
61
58
|
lambda do |action_record, activity|
|
62
59
|
activity.project = action_record[:action].data["board"]["name"]
|
63
60
|
|
64
|
-
activity.project
|
61
|
+
!activity.project.nil?
|
65
62
|
end,
|
66
63
|
|
67
64
|
# Parses the start date
|
@@ -70,7 +67,7 @@ module TimeTrello
|
|
70
67
|
txt_date = action_record[:action].data["text"].scan(/\[[A-Z0-9:. -]+\]/)
|
71
68
|
activity.start_date = DateTime.parse(txt_date[0].to_s).to_time unless txt_date.size == 0
|
72
69
|
|
73
|
-
activity.start_date
|
70
|
+
!activity.start_date.nil?
|
74
71
|
end,
|
75
72
|
|
76
73
|
# Parses the task comment
|
@@ -82,14 +79,18 @@ module TimeTrello
|
|
82
79
|
activity.task_description = action_record[:action].card.name
|
83
80
|
end
|
84
81
|
|
85
|
-
activity.task_description
|
82
|
+
!activity.task_description.nil?
|
83
|
+
end,
|
84
|
+
|
85
|
+
# Parses the task id
|
86
|
+
lambda do |action_record, activity|
|
87
|
+
activity.id = action_record[:action].id
|
88
|
+
|
89
|
+
!activity.id.nil?
|
86
90
|
end
|
87
91
|
]
|
88
92
|
end
|
89
93
|
|
90
|
-
# Private: List of steps that parses the action_record, loading fields of a
|
91
|
-
# provided ActivityRecord instance. It is used as a workflow.
|
92
|
-
|
93
94
|
# Public: Initializes the parser, setting it to the proper state.
|
94
95
|
#
|
95
96
|
# action_record - Hash containing the following elements:
|
@@ -98,26 +99,25 @@ module TimeTrello
|
|
98
99
|
# creator of the action_record with details.
|
99
100
|
# prefix - Prefix to use for comment detection
|
100
101
|
public
|
101
|
-
def initialize(
|
102
|
-
@action_record = action_record
|
102
|
+
def initialize(prefix)
|
103
103
|
@prefix = prefix
|
104
104
|
end
|
105
105
|
|
106
106
|
# Public: Parses the action_record, building an instance of ActivityRecord. This
|
107
107
|
# parser is based on a workflow defined by a constant array of blocks. Each
|
108
108
|
# block is a step that will be executed in sequence.
|
109
|
-
def parse
|
110
|
-
|
109
|
+
def parse(action_record)
|
110
|
+
parsed_record = ActivityRecord.new()
|
111
111
|
|
112
112
|
for step in self.workflow
|
113
|
-
if !step.call(
|
113
|
+
if !step.call(action_record, parsed_record)
|
114
114
|
# Workflow was interrupted. Not necessarily an error. Possibly the
|
115
115
|
# action_record was not the one we are looking for.
|
116
116
|
return nil
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
|
120
|
+
parsed_record
|
121
121
|
end
|
122
122
|
|
123
123
|
end
|
data/lib/time_trello/report.rb
CHANGED
@@ -14,7 +14,16 @@ module TimeTrello
|
|
14
14
|
# structure. It coordinates efforts with the persistence manager in order to
|
15
15
|
# collect data from a given trello board.
|
16
16
|
class Report
|
17
|
+
# Private: Getter for trello driver.
|
18
|
+
protected
|
19
|
+
def driver
|
20
|
+
@driver = TrelloDriver.new(@board_id, @prefix) if @driver == nil
|
21
|
+
|
22
|
+
@driver
|
23
|
+
end
|
24
|
+
|
17
25
|
# Public: Prefix for proper filtering
|
26
|
+
public
|
18
27
|
attr_accessor :prefix
|
19
28
|
# Public: Report start date
|
20
29
|
attr_accessor :start_date
|
@@ -46,8 +55,7 @@ module TimeTrello
|
|
46
55
|
# method. Each element on the array is, in fact, an instance of
|
47
56
|
# TimeTrello::ActivityRecord
|
48
57
|
def find_all &filter
|
49
|
-
|
50
|
-
result_set = driver.activities.find_all { |activity| activity.start_date >= @start_date && activity.start_date <= @end_date }
|
58
|
+
result_set = self.driver.activities.find_all { |activity| activity.start_date >= @start_date && activity.start_date <= @end_date }
|
51
59
|
|
52
60
|
if filter
|
53
61
|
return result_set.find_all &filter
|
@@ -55,6 +63,13 @@ module TimeTrello
|
|
55
63
|
|
56
64
|
result_set
|
57
65
|
end
|
66
|
+
|
67
|
+
def board_id=(board_id)
|
68
|
+
if board_id != @board_id
|
69
|
+
@board_id = board_id
|
70
|
+
self.driver.reset_cache
|
71
|
+
end
|
72
|
+
end
|
58
73
|
|
59
74
|
end
|
60
75
|
end
|
@@ -23,33 +23,76 @@ module TimeTrello
|
|
23
23
|
def initialize(board_id, prefix)
|
24
24
|
@board_id = board_id
|
25
25
|
@prefix = prefix
|
26
|
-
@activities =
|
26
|
+
@activities = nil
|
27
27
|
@board = nil
|
28
|
+
@members = nil
|
29
|
+
@parser = nil
|
28
30
|
end
|
29
31
|
|
32
|
+
# Public: Getter. Returns a record parser instance
|
33
|
+
def parser
|
34
|
+
@parser = Parser.new(@prefix) if @parser.nil?
|
35
|
+
|
36
|
+
@parser
|
37
|
+
end
|
38
|
+
|
30
39
|
# Public: Getter. Gets a board, based on a board id.
|
31
40
|
def board
|
32
|
-
|
41
|
+
retried = false
|
42
|
+
|
43
|
+
begin
|
44
|
+
@board = Trello::Board.find(@board_id) if @board.nil?
|
45
|
+
rescue
|
46
|
+
if !retried
|
47
|
+
retried = true
|
48
|
+
retry
|
49
|
+
else
|
50
|
+
raise "Failed to connect to Trello API"
|
51
|
+
end
|
52
|
+
end
|
33
53
|
|
34
54
|
@board
|
35
55
|
end
|
36
56
|
|
57
|
+
# Public: Getter. Gets all members subscribed to the board under analysis
|
58
|
+
def members
|
59
|
+
retried = false
|
60
|
+
|
61
|
+
begin
|
62
|
+
@members = self.board.members if @members.nil?
|
63
|
+
rescue
|
64
|
+
if !retried
|
65
|
+
retried = true
|
66
|
+
retry
|
67
|
+
else
|
68
|
+
raise "Failed to connect to Trello API"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@members
|
73
|
+
end
|
74
|
+
|
37
75
|
# Public: Getter. Gets all activities for a given board.
|
38
76
|
def activities
|
39
|
-
return @activities if
|
77
|
+
return @activities if !@activities.nil? && @activities.length > 0
|
40
78
|
|
41
79
|
@activities = []
|
42
80
|
self.board.cards.each do |card|
|
43
81
|
card.actions.each do |action|
|
44
|
-
member =
|
82
|
+
member = self.members.first
|
45
83
|
action_record = {action: action, member: member}
|
46
|
-
activity =
|
47
|
-
@activities.push(activity) unless activity
|
84
|
+
activity = self.parser.parse(action_record)
|
85
|
+
@activities.push(activity) unless activity.nil?
|
48
86
|
end
|
49
87
|
end
|
50
88
|
|
51
89
|
@activities
|
52
90
|
end
|
53
91
|
|
92
|
+
# Public: Resets the driver caches
|
93
|
+
def reset_cache
|
94
|
+
@activities = nil
|
95
|
+
@board = nil
|
96
|
+
end
|
54
97
|
end
|
55
98
|
end
|
data/lib/time_trello/version.rb
CHANGED
data/lib/time_trello.rb
CHANGED
@@ -17,7 +17,7 @@ module TimeTrello
|
|
17
17
|
# Private: Prefix for comment detection/parsing
|
18
18
|
private
|
19
19
|
attr_accessor :prefix
|
20
|
-
|
20
|
+
|
21
21
|
# Public: Initializes this module with the proper trello client configuration.
|
22
22
|
#
|
23
23
|
# public_key - Trello public key used for authentication.
|
@@ -40,7 +40,21 @@ module TimeTrello
|
|
40
40
|
# filter - A block containing a filter for the results. The block must receive
|
41
41
|
# a parameter which is an instance of ActivityRecord.
|
42
42
|
def self.find_all(start_date, end_date, board_id, &filter)
|
43
|
-
|
43
|
+
self.report(start_date, end_date, board_id).find_all(&filter)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Private: Getter for a report instance. Guarantees only one single instance
|
47
|
+
# available for caching optimization.
|
48
|
+
def self.report(start_date, end_date, board_id)
|
49
|
+
if @report == nil
|
50
|
+
@report = Report.new(start_date, end_date, board_id, @prefix)
|
51
|
+
else
|
52
|
+
# Updates report parameters
|
53
|
+
@report.start_date = start_date
|
54
|
+
@report.end_date = end_date
|
55
|
+
@report.board_id = board_id
|
56
|
+
end
|
57
|
+
|
58
|
+
@report
|
44
59
|
end
|
45
|
-
|
46
60
|
end
|
data/readme.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# TimeTrello
|
2
|
+
|
3
|
+
**TimeTrello** is a simple gem that can interpret special trello comments. Those
|
4
|
+
comments are then converted to a record type that makes it easy to integrate a
|
5
|
+
time tracking application with Trello.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'timetrello'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```console
|
17
|
+
bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```console
|
23
|
+
gem install timetrello
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
You use the module directly.
|
30
|
+
|
31
|
+
### Trello
|
32
|
+
|
33
|
+
All time tracking annotations must follow the specification below in order to be
|
34
|
+
understood and consolidated by **TimeTrello**.
|
35
|
+
|
36
|
+
**PREFIX** **DURATION** [**START_DATE**] "**COMMENT**"
|
37
|
+
|
38
|
+
See some valid examples:
|
39
|
+
|
40
|
+
- :clock12: 0:35
|
41
|
+
- :clock12: 102:22 "A comment example."
|
42
|
+
- :clock12: 00:05 [2016-04-01]
|
43
|
+
- :clock12: 007:59 [2012-03-17 21:50Z] "Other comment example."
|
44
|
+
|
45
|
+
The default prefix which identifies the proper comment is :clock12:
|
46
|
+
(`:clock12:`) emoticon. If no start date is provided through the comment, the
|
47
|
+
comment timestamp is used.
|
48
|
+
|
49
|
+
### Ruby
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'time_trello'
|
53
|
+
|
54
|
+
TimeTrello.initialize('your trello public key here', 'your trello token here', ':clock12:')
|
55
|
+
tasks = TimeTrello.find_all(Time.new(2012, 1, 1), Time.new(2016, 4, 1), 'Board ID you want to evaluate')
|
56
|
+
|
57
|
+
tasks.each do |task|
|
58
|
+
# ...
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
## Methods
|
63
|
+
|
64
|
+
### `initialize`
|
65
|
+
|
66
|
+
Initializes the **TimeTrello** subsystem, providing information necessary for its
|
67
|
+
proper workings.
|
68
|
+
|
69
|
+
#### Parameters
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
TimeTrello.initialize(public_key, token, prefix=':clock12:')
|
73
|
+
```
|
74
|
+
|
75
|
+
| Parameter | Type | Description |
|
76
|
+
|---|:---:|---|
|
77
|
+
| **`public_key`** | `String` | Your Trello developer key |
|
78
|
+
| **`token`** | `String` | The connection token provided by Trello due to its authorization process |
|
79
|
+
| **`prefix`** | `String` | Prefix to use for comment detection. Defaults to `:clock12:` |
|
80
|
+
|
81
|
+
### `find_all`
|
82
|
+
|
83
|
+
Queries Trello, parsing comments which have the required format for consolidation.
|
84
|
+
|
85
|
+
#### Parameters
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
TimeTrello.find_all (start_date, end_date, board_id, &filter)
|
89
|
+
```
|
90
|
+
|
91
|
+
| Parameter | Type | Description |
|
92
|
+
|---|:---:|---|
|
93
|
+
| **`start_date`** | `Time` | Start date to use for limiting the result set |
|
94
|
+
| **`end_date`** | `Time` | End date to use for limiting the result set |
|
95
|
+
| **`board_id`** | `String` | Trello's board identification to query for |
|
96
|
+
| **`filter`** | `Proc` | Block to use for extra data filtering |
|
97
|
+
|
98
|
+
The `filter` block receives as parameter an instance of
|
99
|
+
`TimeTrello::ActivityRecord`. It must return a boolean:
|
100
|
+
|
101
|
+
- `true`: the entry will be on the final result set
|
102
|
+
- `false`: the entry will de discarded from final result set
|
103
|
+
|
104
|
+
See the `example.rb` file for a usage example.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timetrello
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Tarifa
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-trello
|
@@ -37,7 +37,8 @@ email:
|
|
37
37
|
- ronaldo@nineteen.com.br
|
38
38
|
executables: []
|
39
39
|
extensions: []
|
40
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
41
|
+
- readme.md
|
41
42
|
files:
|
42
43
|
- lib/time_trello.rb
|
43
44
|
- lib/time_trello/activity_record.rb
|
@@ -46,12 +47,14 @@ files:
|
|
46
47
|
- lib/time_trello/report.rb
|
47
48
|
- lib/time_trello/trello_driver.rb
|
48
49
|
- lib/time_trello/version.rb
|
49
|
-
|
50
|
+
- readme.md
|
51
|
+
homepage: http://formaweb.github.io/timetrello
|
50
52
|
licenses:
|
51
53
|
- MIT
|
52
54
|
metadata: {}
|
53
55
|
post_install_message:
|
54
|
-
rdoc_options:
|
56
|
+
rdoc_options:
|
57
|
+
- "--charset=UTF-8"
|
55
58
|
require_paths:
|
56
59
|
- lib
|
57
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|