time_distribution 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.md +17 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/time_distribution/smart_duration.rb +22 -0
- data/lib/time_distribution/task.rb +21 -0
- data/lib/time_distribution/time.rb +11 -0
- data/lib/time_distribution/version.rb +3 -0
- data/lib/time_distribution/work_day.rb +29 -0
- data/lib/time_distribution.rb +9 -0
- data/time_distribution.gemspec +26 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
License
|
2
|
+
=========
|
3
|
+
|
4
|
+
Copyright © 2012 by the Computer Poker Research Group, University of Alberta.
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
Except as contained in this notice, the name(s) of the above copyright holders shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
13
|
+
|
14
|
+
Credits
|
15
|
+
-------
|
16
|
+
|
17
|
+
Dustin Morrill: morrill@ualberta.ca
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TimeDistribution
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'time_distribution'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install time_distribution
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'chronic_duration'
|
3
|
+
require 'ruby-duration'
|
4
|
+
|
5
|
+
require_relative 'time'
|
6
|
+
|
7
|
+
module SmartDuration
|
8
|
+
def self.parse(time_period)
|
9
|
+
# If the time period has is something like 1:00pm to 1:30pm or 1-2, interpret it as a range
|
10
|
+
time_of_day_pattern = '\d+:?\d*[ap]?m?'
|
11
|
+
|
12
|
+
Duration.new(
|
13
|
+
if time_period.to_s.downcase.match(
|
14
|
+
/(#{time_of_day_pattern})\s*(to|-)\s*(#{time_of_day_pattern})/
|
15
|
+
)
|
16
|
+
Chronic.parse($1).count_forward_to(Chronic.parse($3))
|
17
|
+
else
|
18
|
+
ChronicDuration.parse(time_period)
|
19
|
+
end
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'chronic_duration'
|
2
|
+
|
3
|
+
require_relative 'smart_duration'
|
4
|
+
|
5
|
+
class Task
|
6
|
+
attr_reader :subject, :time_taken, :desc
|
7
|
+
|
8
|
+
# @param [#to_s] subject The subject on which the task was completed. E.g. A course or project.
|
9
|
+
# @param [#to_s] time_taken The amount of time taken on the task (Compatible with +ChronicDuration+ parsing, or a range of times that conform to +Chronic+ parsing).
|
10
|
+
# @param [#to_s] desc The task's description.
|
11
|
+
def initialize(subject, time_taken, desc)
|
12
|
+
@subject = subject
|
13
|
+
@time_taken = SmartDuration.parse(time_taken)
|
14
|
+
@desc = desc
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
# @todo Format time properly
|
19
|
+
"#{ChronicDuration.parse(@time_taken.total)} spent on #{@subject}: #{@desc}"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'chronic'
|
2
|
+
require 'ruby-duration'
|
3
|
+
|
4
|
+
class WorkDay
|
5
|
+
attr_reader :date, :tasks
|
6
|
+
|
7
|
+
# @param [#to_s] date Date of this work day in +Chronic+ compatible format.
|
8
|
+
# @param [Array<Task>] tasks List of tasks done in this work day. Defaults to an empty list.
|
9
|
+
def initialize(date, tasks=[])
|
10
|
+
@date = Chronic.parse(date)
|
11
|
+
@tasks = tasks
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param [Task] task Adds +task+ to the list of tasks completed on this work day.
|
15
|
+
def add_task!(task)
|
16
|
+
@tasks << task
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def time_worked
|
22
|
+
times = {}
|
23
|
+
@tasks.inject({}) do |times, t|
|
24
|
+
times[t.subject] = Duration.new(0) unless times[t.subject]
|
25
|
+
times[t.subject] += t.time_taken
|
26
|
+
times
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative "time_distribution/version"
|
2
|
+
|
3
|
+
require_relative 'time_distribution/time'
|
4
|
+
|
5
|
+
module TimeDistribution
|
6
|
+
require_relative 'time_distribution/smart_duration'
|
7
|
+
require_relative 'time_distribution/task'
|
8
|
+
require_relative 'time_distribution/work_day'
|
9
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'time_distribution/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "time_distribution"
|
8
|
+
gem.version = TimeDistribution::VERSION
|
9
|
+
gem.authors = ["Dustin"]
|
10
|
+
gem.email = ["morrill@ualberta.ca"]
|
11
|
+
gem.description = %q{Gem for creating time distribution management systems}
|
12
|
+
gem.summary = %q{Gem for creating time distribution management systems}
|
13
|
+
gem.homepage = ""
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "chronic"
|
22
|
+
gem.add_dependency "chronic_duration"
|
23
|
+
gem.add_dependency "ruby-duration"
|
24
|
+
|
25
|
+
gem.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: time_distribution
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dustin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chronic
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: chronic_duration
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-duration
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Gem for creating time distribution management systems
|
79
|
+
email:
|
80
|
+
- morrill@ualberta.ca
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.md
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/time_distribution.rb
|
91
|
+
- lib/time_distribution/smart_duration.rb
|
92
|
+
- lib/time_distribution/task.rb
|
93
|
+
- lib/time_distribution/time.rb
|
94
|
+
- lib/time_distribution/version.rb
|
95
|
+
- lib/time_distribution/work_day.rb
|
96
|
+
- time_distribution.gemspec
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Gem for creating time distribution management systems
|
122
|
+
test_files: []
|
123
|
+
has_rdoc:
|