time_report 0.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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/bin/time_report +12 -0
- data/lib/time_report.rb +8 -0
- data/lib/time_report/day.rb +20 -0
- data/lib/time_report/duration.rb +8 -0
- data/lib/time_report/processor.rb +66 -0
- data/lib/time_report/task.rb +44 -0
- data/lib/time_report/version.rb +3 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/time_report/task_spec.rb +27 -0
- data/spec/time_report_spec.rb +32 -0
- data/time_report.gemspec +24 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f3d8056ed653511d1dde801f60e2e968e12ccfb
|
4
|
+
data.tar.gz: 1cd562e2cd413d66f7369d99e469186110d0055c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f1aada79962d8843372115d974ca4ada8b35511bd142b95cbbaa76451421c95e389d9e69dd1d87c0a1e3992a5eb2cbed5c9bd83580a7eddabf9da3e06257190
|
7
|
+
data.tar.gz: ef71f04fa502529b0905c7f965a707377e0becdabc87978fc151798a625010d079ed452cd79fad0dbc03d6114ffe85d15e2aae1bb79ca270e1866ce517731d59
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Pavel Gabriel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TimeReport
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'time_report'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install time_report
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/time_report/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/time_report
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
4
|
+
|
5
|
+
require 'time_report'
|
6
|
+
|
7
|
+
report_file = ARGV[0] || 'tasks.todo'
|
8
|
+
content = File.read(report_file)
|
9
|
+
report = TimeReport::Processor.new(content)
|
10
|
+
report.run
|
11
|
+
|
12
|
+
puts report.output
|
data/lib/time_report.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class TimeReport::Day
|
2
|
+
include TimeReport::Duration
|
3
|
+
|
4
|
+
attr_accessor :date
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_task(task)
|
10
|
+
tasks << TimeReport::Task.new(task)
|
11
|
+
end
|
12
|
+
|
13
|
+
def tasks
|
14
|
+
@tasks ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def duration
|
18
|
+
tasks.inject(0) { |sum, task| sum + task.duration }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class TimeReport::Processor
|
2
|
+
attr_reader :input
|
3
|
+
|
4
|
+
def initialize(input)
|
5
|
+
@input = input
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
parse
|
10
|
+
generate
|
11
|
+
end
|
12
|
+
|
13
|
+
def output
|
14
|
+
@output ||= ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate
|
18
|
+
days.each do |day|
|
19
|
+
output << "#{day.in_hours} # #{day.date}\n"
|
20
|
+
day.tasks.each do |task|
|
21
|
+
output << "#{task.in_hours} # #{task.description}\n"
|
22
|
+
end
|
23
|
+
output << "\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
output << "Perfecto!\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse
|
30
|
+
day = nil
|
31
|
+
|
32
|
+
input.each_line do |line|
|
33
|
+
line = line.chomp
|
34
|
+
|
35
|
+
if date?(line)
|
36
|
+
day = TimeReport::Day.new
|
37
|
+
day.date = line
|
38
|
+
add_day(day)
|
39
|
+
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
43
|
+
if task?(line)
|
44
|
+
day.add_task(line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_day(day)
|
50
|
+
days << day
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def days
|
56
|
+
@days ||= []
|
57
|
+
end
|
58
|
+
|
59
|
+
def date?(line)
|
60
|
+
line =~ /\d{1,2}\.\d{1,2}/
|
61
|
+
end
|
62
|
+
|
63
|
+
def task?(line)
|
64
|
+
line =~ TimeReport::Task::REG_EXP
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class TimeReport::Task
|
2
|
+
REG_EXP = /
|
3
|
+
(?<start_hour>\d{1,2}):(?<start_minutes>\d{1,2})
|
4
|
+
\s*-\s*
|
5
|
+
(?<end_hour>\d{1,2}):(?<end_minutes>\d{1,2})
|
6
|
+
\s+
|
7
|
+
(?<description>.+)
|
8
|
+
\z
|
9
|
+
/x
|
10
|
+
|
11
|
+
include TimeReport::Duration
|
12
|
+
|
13
|
+
attr_reader :task_string
|
14
|
+
|
15
|
+
def initialize(task_string)
|
16
|
+
@task_string = task_string
|
17
|
+
end
|
18
|
+
|
19
|
+
def duration
|
20
|
+
match = REG_EXP.match(task_string)
|
21
|
+
|
22
|
+
if match
|
23
|
+
start_hour = match[:start_hour].to_i
|
24
|
+
start_minutes = match[:start_minutes].to_i
|
25
|
+
|
26
|
+
end_hour = match[:end_hour].to_i
|
27
|
+
end_minutes = match[:end_minutes].to_i
|
28
|
+
|
29
|
+
(end_hour*60 + end_minutes) - (start_hour*60 + start_minutes)
|
30
|
+
else
|
31
|
+
0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def description
|
36
|
+
match = REG_EXP.match(task_string)
|
37
|
+
|
38
|
+
if match
|
39
|
+
match[:description]
|
40
|
+
else
|
41
|
+
"n/a"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TimeReport::Task do
|
4
|
+
def task(line)
|
5
|
+
TimeReport::Task.new(line)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "TimeReport::Task::REG_EXP" do
|
9
|
+
it "matches all task strings" do
|
10
|
+
expect("10:00 - 12:40 Task description").to match(TimeReport::Task::REG_EXP)
|
11
|
+
expect("o 10:00 - 12:40 Task description").to match(TimeReport::Task::REG_EXP)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#duration" do
|
16
|
+
it "returns duration in minutes" do
|
17
|
+
expect(task("10:00 - 12:40 Task description").duration).to be(160)
|
18
|
+
expect(task("1:00 - 2:40 Task description").duration).to be(100)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#description" do
|
23
|
+
it "returns description" do
|
24
|
+
expect(task("10:00 - 12:40 Task description").description).to eq("Task description")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TimeReport do
|
4
|
+
describe "#output" do
|
5
|
+
it "returns tasks with time for each day" do
|
6
|
+
input = <<-JSON
|
7
|
+
22.01
|
8
|
+
10:00 - 11:31 First task 1
|
9
|
+
11:40 - 12:00 Last task 2
|
10
|
+
|
11
|
+
21.01
|
12
|
+
06:00 - 08:00 First task 3
|
13
|
+
09:00 - 10:00 Last task 4
|
14
|
+
JSON
|
15
|
+
|
16
|
+
report = TimeReport::Processor.new(input)
|
17
|
+
report.run
|
18
|
+
|
19
|
+
expect(report.output).to eq(<<-OUT)
|
20
|
+
01:51 # 22.01
|
21
|
+
01:31 # First task 1
|
22
|
+
00:20 # Last task 2
|
23
|
+
|
24
|
+
03:00 # 21.01
|
25
|
+
02:00 # First task 3
|
26
|
+
01:00 # Last task 4
|
27
|
+
|
28
|
+
Perfecto!
|
29
|
+
OUT
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/time_report.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'time_report/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "time_report"
|
8
|
+
spec.version = TimeReport::VERSION
|
9
|
+
spec.authors = ["Pavel Gabriel"]
|
10
|
+
spec.email = ["alovak@gmail.com"]
|
11
|
+
spec.summary = %q{Simple time reporting for simple todos}
|
12
|
+
spec.description = %q{Time reporting gem for plain text todos}
|
13
|
+
spec.homepage = "http://github.com/alovak/time_report"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: time_report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Gabriel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-28 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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
|
+
description: Time reporting gem for plain text todos
|
56
|
+
email:
|
57
|
+
- alovak@gmail.com
|
58
|
+
executables:
|
59
|
+
- time_report
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/time_report
|
71
|
+
- lib/time_report.rb
|
72
|
+
- lib/time_report/day.rb
|
73
|
+
- lib/time_report/duration.rb
|
74
|
+
- lib/time_report/processor.rb
|
75
|
+
- lib/time_report/task.rb
|
76
|
+
- lib/time_report/version.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/time_report/task_spec.rb
|
79
|
+
- spec/time_report_spec.rb
|
80
|
+
- time_report.gemspec
|
81
|
+
homepage: http://github.com/alovak/time_report
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.3.0
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Simple time reporting for simple todos
|
105
|
+
test_files:
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/time_report/task_spec.rb
|
108
|
+
- spec/time_report_spec.rb
|