togglapper 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/lib/togglapper.rb +7 -0
- data/lib/togglapper/client_module.rb +28 -0
- data/lib/togglapper/config.rb +2 -0
- data/lib/togglapper/params.rb +50 -0
- data/lib/togglapper/report.rb +6 -0
- data/lib/togglapper/reports/base.rb +32 -0
- data/lib/togglapper/search.rb +13 -0
- data/lib/togglapper/searches/.tag.rb.swp +0 -0
- data/lib/togglapper/searches/base.rb +96 -0
- data/lib/togglapper/searches/date.rb +50 -0
- data/lib/togglapper/searches/description.rb +9 -0
- data/lib/togglapper/searches/now.rb +38 -0
- data/lib/togglapper/searches/tag.rb +20 -0
- data/lib/togglapper/summaries/date.rb +44 -0
- data/lib/togglapper/summaries/tag.rb +11 -0
- data/lib/togglapper/summary.rb +8 -0
- data/lib/togglapper/version.rb +3 -0
- data/togglapper.gemspec +42 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a21b384a4cb44d4423208ab4e08c6fed9807e836
|
4
|
+
data.tar.gz: c4a54efc71efff6249fc7413f81ccad887a9ff68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dc09bc4299fd72ffb925256a7e1f62504cd98b8005ef0940816960d692820a7f775024719e62a160a946374e665c046e1b8c051bb2307da67b1a4c34e2dddb3
|
7
|
+
data.tar.gz: 750e258ede943dae31b3757b85042226bfefdfb09fb0a103e81953e07c49cc27944f7d21a840ec764cc5350e3804d184d484c258d72f221f7d977f9c2ca8d0a9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at toririn.paftako@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 toririn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Togglapper
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/togglapper`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'togglapper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install togglapper
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/togglapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "togglapper"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
require "pry"
|
15
|
+
require "pry-rails"
|
16
|
+
require "pry-byebug"
|
17
|
+
#IRB.start
|
18
|
+
|
19
|
+
client = Togglapper::Client.new
|
20
|
+
client.summary_by_tags("#2661")
|
21
|
+
binding.pry
|
22
|
+
puts "end"
|
data/bin/setup
ADDED
data/lib/togglapper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'togglv8'
|
2
|
+
require 'togglapper/search'
|
3
|
+
require 'togglapper/summary'
|
4
|
+
require 'togglapper/report'
|
5
|
+
require 'togglapper/params'
|
6
|
+
require "togglapper/version"
|
7
|
+
|
8
|
+
module Togglapper
|
9
|
+
module ClientModule
|
10
|
+
include Togglapper::Search
|
11
|
+
include Togglapper::Params
|
12
|
+
include Togglapper::Summary
|
13
|
+
include Togglapper::Report
|
14
|
+
|
15
|
+
URL = "https://toggl.com/"
|
16
|
+
TIMER_URL = "#{URL}app/timer"
|
17
|
+
|
18
|
+
attr_accessor :client
|
19
|
+
|
20
|
+
def initialize(api_token = ENV['TOGGL_API_TOKEN'])
|
21
|
+
@client = TogglV8::API.new(api_token)
|
22
|
+
end
|
23
|
+
|
24
|
+
def configure
|
25
|
+
yield self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "togglapper/client_module"
|
2
|
+
module Togglapper
|
3
|
+
module Params
|
4
|
+
def user
|
5
|
+
@user ||= client.me
|
6
|
+
end
|
7
|
+
|
8
|
+
def workspaces
|
9
|
+
@workspaces ||= client.gc.my_workspaces(user)
|
10
|
+
end
|
11
|
+
|
12
|
+
def workspace(id: nil, name: nil)
|
13
|
+
if id
|
14
|
+
workspaces.find{ |work| work["id"] == id }
|
15
|
+
elsif name
|
16
|
+
workspaces.find{ |work| work["name"] == name }
|
17
|
+
else
|
18
|
+
workspaces.first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def projects
|
23
|
+
@projects ||= client.gc.my_projects
|
24
|
+
end
|
25
|
+
|
26
|
+
def project(id: nil, name: nil)
|
27
|
+
if id
|
28
|
+
projects.find{ |project| project["id"] == id }
|
29
|
+
elsif name
|
30
|
+
projects.find{ |project| project["name"] == name }
|
31
|
+
else
|
32
|
+
projects.first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def tags
|
37
|
+
@tags ||= client.gc.my_tags
|
38
|
+
end
|
39
|
+
|
40
|
+
def tag(id: nil, name: nil)
|
41
|
+
if id
|
42
|
+
tags.find{ |tag| tag["id"] == id }
|
43
|
+
elsif name
|
44
|
+
tags.find{ |tag| tag["name"] == name }
|
45
|
+
else
|
46
|
+
tags.first
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Togglapper
|
2
|
+
module Reports
|
3
|
+
module Base
|
4
|
+
def report_by_summary(summary)
|
5
|
+
entries_reports = []
|
6
|
+
summary[:entries].each do |entry|
|
7
|
+
entries_reports << "#{entry[:description]}/#{display_tags(entry[:tags])}: #{entry[:work_time]}s"
|
8
|
+
end
|
9
|
+
|
10
|
+
"合計: #{display_time(summary[:summary_time])}\n詳細:\n * #{entries_reports.join("\n * ")}"
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def display_tags(tags)
|
17
|
+
return 'tagなし' if tags.nil? || tags.empty?
|
18
|
+
tags.join(",")
|
19
|
+
end
|
20
|
+
|
21
|
+
def display_time(time_s)
|
22
|
+
return '0.0h' if time_s == 0
|
23
|
+
time_h = time_s.to_f/3600
|
24
|
+
if time_h < 0.1
|
25
|
+
"#{(time_h * 60).round(2)}m"
|
26
|
+
else
|
27
|
+
"#{time_h.round(2)}h"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'togglapper/searches/now'
|
2
|
+
require 'togglapper/searches/description'
|
3
|
+
require 'togglapper/searches/tag'
|
4
|
+
require 'togglapper/searches/date'
|
5
|
+
|
6
|
+
module Togglapper
|
7
|
+
module Search
|
8
|
+
include Searches::Now
|
9
|
+
include Searches::Description
|
10
|
+
include Searches::Tag
|
11
|
+
include Searches::Date
|
12
|
+
end
|
13
|
+
end
|
Binary file
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'togglv8'
|
2
|
+
require "togglapper/client_module"
|
3
|
+
module Togglapper
|
4
|
+
module Searches
|
5
|
+
module Base
|
6
|
+
|
7
|
+
# entry = toggl の個タスク
|
8
|
+
# APIの持ち主の entry 一覧を取得する
|
9
|
+
# ex: entryの中身
|
10
|
+
# {
|
11
|
+
# "id"=>491600812,
|
12
|
+
# "wid"=>1552948,
|
13
|
+
# "billable"=>false,
|
14
|
+
# "start"=>"2016-12-01T15:42:21+00:00",
|
15
|
+
# "stop"=>"2016-12-01T15:42:53+00:00",
|
16
|
+
# "duration"=>32,
|
17
|
+
# "description"=>"aaa",
|
18
|
+
# "tags"=>["#2661"],
|
19
|
+
# "duronly"=>false,
|
20
|
+
# "at"=>"2016-12-01T15:42:53+00:00",
|
21
|
+
# "uid"=>2344433},
|
22
|
+
# }
|
23
|
+
def entries(refresh: false)
|
24
|
+
if refresh
|
25
|
+
@entries = client.my_time_entries
|
26
|
+
else
|
27
|
+
@entries ||= client.my_time_entries
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def latest_entry
|
32
|
+
entries.sort_by{ |entry| entry["start"] }.last
|
33
|
+
end
|
34
|
+
|
35
|
+
def working_entry
|
36
|
+
if latest_entry["stop"].nil?
|
37
|
+
latest_entry
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# entry 情報からその entry にどれだけの時間を使ったか返す。
|
42
|
+
# 返すのは基本的にUnix 秒。ただし format を指定すれば時間や分の単位で返す。
|
43
|
+
def get_diff_time_by_entry(entry = latest_entry, format = nil)
|
44
|
+
if entry["duration"] && entry["stop"]
|
45
|
+
diff_time = entry["duration"]
|
46
|
+
else
|
47
|
+
# 現在作業中(終了時間がない)であれば現在日時を終了時間として取得
|
48
|
+
stop_time_org = Time.now
|
49
|
+
|
50
|
+
# 差分の時間数を計算
|
51
|
+
start_time = Time.parse(entry["start"]).getlocal("+09:00")
|
52
|
+
stop_time = stop_time_org.getlocal("+09:00")
|
53
|
+
diff_time = stop_time - start_time
|
54
|
+
end
|
55
|
+
|
56
|
+
if format.nil?
|
57
|
+
diff_time.to_i
|
58
|
+
elsif format == '%H' || format == '%h'
|
59
|
+
diff_time/3600
|
60
|
+
elsif format == '%M' || format == '%m'
|
61
|
+
diff_time/60
|
62
|
+
elsif format == '%S' || format == '%s'
|
63
|
+
diff_time.to_i
|
64
|
+
else
|
65
|
+
raise 'invalid format: #{format}. exsample: %H(h), %M(m), %S(s)'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# entry 情報から「タグ情報」「説明文(Description)」「タスク実績時間」を取得する
|
70
|
+
def entry_info(entry = latest_entry)
|
71
|
+
work_time = get_diff_time_by_entry(entry, '%S')
|
72
|
+
tags = entry["tags"] || nil
|
73
|
+
description = entry["description"] || nil
|
74
|
+
|
75
|
+
{ description: description, tags: tags, work_time: work_time }
|
76
|
+
end
|
77
|
+
|
78
|
+
# entry info の String Version
|
79
|
+
def entry_info_string(entry = latest_entry)
|
80
|
+
diff_time = get_diff_time_by_entry(entry, '%H')
|
81
|
+
|
82
|
+
# 差分時間が 0.1h 以下の表示になるようであれば 分表示に変更する
|
83
|
+
if diff_time >= 0.1
|
84
|
+
work_time = "#{diff_time.round(2)}h"
|
85
|
+
else
|
86
|
+
work_time = "#{(diff_time * 60).round(2)}m"
|
87
|
+
end
|
88
|
+
|
89
|
+
tag = entry["tags"].join(" ") unless entry["tags"].nil?
|
90
|
+
description = entry["description"]
|
91
|
+
|
92
|
+
"#{tag} #{description} \(#{work_time}\)"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Togglapper
|
2
|
+
module Searches
|
3
|
+
module Date
|
4
|
+
|
5
|
+
def entries_by_date(target_date = Time.now.to_date)
|
6
|
+
entries.select do |entry|
|
7
|
+
start_date = Time.parse(entry["start"]).getlocal("+09:00").to_date
|
8
|
+
start_date_in_target_date?(start_date, target_date)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def entries_by_this_week
|
13
|
+
today = Time.now.to_date
|
14
|
+
this_monday = today - (today.wday - 1)
|
15
|
+
entries.select do |entry|
|
16
|
+
start_date = Time.parse(entry["start"]).getlocal("+09:00").to_date
|
17
|
+
start_date_in_target_date?(start_date, this_monday..today)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def entries_by_this_month
|
22
|
+
begin_month_day = Date.new(Time.now.year, Time.now.month, 1)
|
23
|
+
end_month_day = Date.new(Time.now.year, Time.now.month, -1)
|
24
|
+
entries.select do |entry|
|
25
|
+
start_date = Time.parse(entry["start"]).getlocal("+09:00").to_date
|
26
|
+
start_date_in_target_date?(start_date, begin_month_day..end_month_day)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :entries_by_today, :entries_by_date
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def start_date_in_target_date?(start_date, target_date)
|
35
|
+
case target_date.class.to_s
|
36
|
+
when "Date"
|
37
|
+
start_date == target_date
|
38
|
+
when "Range", "Array"
|
39
|
+
target_date.include?(start_date)
|
40
|
+
when "String"
|
41
|
+
start_date == Date.parse(target_date) rescue raise "invalid target_date format: #{target_date}. format is yyyy/mm/dd"
|
42
|
+
when "Time"
|
43
|
+
start_date == target_date.to_date
|
44
|
+
else
|
45
|
+
raise "invalid date format: #{target_date.class}. format is Date, Range, String, Array, Time"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Togglapper
|
2
|
+
module Searches
|
3
|
+
module Now
|
4
|
+
def entries(refresh: false)
|
5
|
+
if refresh
|
6
|
+
@entries = toggl_client.my_time_entries
|
7
|
+
else
|
8
|
+
@entries ||= toggl_client.my_time_entries
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def day_entries(day = Time.now.to_date)
|
13
|
+
entries.select do |entry|
|
14
|
+
start_date = Time.parse(entry["start"]).getlocal("+09:00").to_date
|
15
|
+
start_date == day
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def entries_by_tags(*tags)
|
20
|
+
entries.select do |entry|
|
21
|
+
tags.map(&:to_s).all? do |tag|
|
22
|
+
entry["tags"] && entry["tags"].include?(tag)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def latest_entry
|
28
|
+
entries.sort_by{ |entry| entry["start"] }.last
|
29
|
+
end
|
30
|
+
|
31
|
+
def working_entry
|
32
|
+
if latest_entry["stop"].nil?
|
33
|
+
latest_entry
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'togglapper/searches/base'
|
2
|
+
module Togglapper
|
3
|
+
module Searches
|
4
|
+
module Tag
|
5
|
+
include Togglapper::Searches::Base
|
6
|
+
|
7
|
+
def entries_by_tags(*tags)
|
8
|
+
entries_by_tags_for(self.entries, tags)
|
9
|
+
end
|
10
|
+
|
11
|
+
def entries_by_tags_for(entries, *tags)
|
12
|
+
entries.select do |entry|
|
13
|
+
tags.flatten.map(&:to_s).all? do |tag|
|
14
|
+
entry["tags"] && entry["tags"].include?(tag)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Togglapper
|
2
|
+
module Summaries
|
3
|
+
module Date
|
4
|
+
def dailyreport
|
5
|
+
today_entry_reports
|
6
|
+
end
|
7
|
+
|
8
|
+
def daily_by_tags(*search_tags)
|
9
|
+
day_entries = entry_info(entries_by_today)
|
10
|
+
day_entries.select do |entry|
|
11
|
+
entry[:tags] && entry[:tags].any? { |tag| search_tags.include?(tag) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def daily_by_description(description)
|
16
|
+
day_entries = entry_info(entries_by_today)
|
17
|
+
day_entries.select do |entry|
|
18
|
+
entry[:description] && entryentry[:description] =~ description
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def today_entry_reports
|
25
|
+
reports = []
|
26
|
+
day_entries.each do |entry|
|
27
|
+
reports << entry_info(entry)
|
28
|
+
end
|
29
|
+
|
30
|
+
report_group =
|
31
|
+
reports.group_by do |report|
|
32
|
+
report["description"]
|
33
|
+
end
|
34
|
+
|
35
|
+
today_reports =
|
36
|
+
report_group.map do |discription, entrys|
|
37
|
+
sum_time = entrys.inject(0){|sum, entry| sum + entry["work_time"] }
|
38
|
+
"#{discription} \(#{(sum_time/60).round(1)}.h\)"
|
39
|
+
end
|
40
|
+
today_reports.join("\n")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Togglapper
|
2
|
+
module Summaries
|
3
|
+
module Tag
|
4
|
+
def summary_by_tags(*search_tags)
|
5
|
+
entries = entries_by_tags(search_tags).map { |entry| entry_info(entry) }
|
6
|
+
summary_time = entries.inject(0) { |sum, entry| sum = sum + entry[:work_time] }
|
7
|
+
{ entries: entries, summary_time: summary_time }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/togglapper.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'togglapper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "togglapper"
|
8
|
+
spec.version = Togglapper::VERSION
|
9
|
+
spec.authors = ["toririn"]
|
10
|
+
spec.email = ["toririn.paftako@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{use toggl api.}
|
13
|
+
spec.description = %q{use toggl api.}
|
14
|
+
spec.homepage = "https://github.com/toririn/togglapper"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
spec.add_development_dependency "pry-rails"
|
38
|
+
spec.add_development_dependency "pry-byebug"
|
39
|
+
|
40
|
+
spec.add_dependency "awesome_print"
|
41
|
+
spec.add_dependency "togglv8"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: togglapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- toririn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awesome_print
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: togglv8
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: use toggl api.
|
126
|
+
email:
|
127
|
+
- toririn.paftako@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/togglapper.rb
|
143
|
+
- lib/togglapper/client_module.rb
|
144
|
+
- lib/togglapper/config.rb
|
145
|
+
- lib/togglapper/params.rb
|
146
|
+
- lib/togglapper/report.rb
|
147
|
+
- lib/togglapper/reports/base.rb
|
148
|
+
- lib/togglapper/search.rb
|
149
|
+
- lib/togglapper/searches/.tag.rb.swp
|
150
|
+
- lib/togglapper/searches/base.rb
|
151
|
+
- lib/togglapper/searches/date.rb
|
152
|
+
- lib/togglapper/searches/description.rb
|
153
|
+
- lib/togglapper/searches/now.rb
|
154
|
+
- lib/togglapper/searches/tag.rb
|
155
|
+
- lib/togglapper/summaries/date.rb
|
156
|
+
- lib/togglapper/summaries/tag.rb
|
157
|
+
- lib/togglapper/summary.rb
|
158
|
+
- lib/togglapper/version.rb
|
159
|
+
- togglapper.gemspec
|
160
|
+
homepage: https://github.com/toririn/togglapper
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata:
|
164
|
+
allowed_push_host: https://rubygems.org
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.5.1
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: use toggl api.
|
185
|
+
test_files: []
|