timer.rb 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.
- data/LICENSE +20 -0
- data/README.markdown +44 -0
- data/Rakefile +13 -0
- data/bin/foo.rb +3 -0
- data/bin/timer.rb +15 -0
- data/lib/timer.rb +3 -0
- data/lib/timer/time_parser.rb +33 -0
- data/lib/timer/timer.rb +9 -0
- data/lib/timer/version.rb +3 -0
- metadata +98 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Federico Builes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
timer.rb
|
2
|
+
=======
|
3
|
+
|
4
|
+
timer.rb is a simple command line timer written in Ruby. It uses OS X voice commands to let you know
|
5
|
+
when it's hammer time!
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
------------
|
9
|
+
* Ruby
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
You can install from Rubygems
|
15
|
+
|
16
|
+
$ gem install timer.rb
|
17
|
+
|
18
|
+
Or you can download the source and build it manually:
|
19
|
+
|
20
|
+
$ git clone https://febuiles@github.com/febuiles/timer.rb.git
|
21
|
+
$ rake install
|
22
|
+
|
23
|
+
|
24
|
+
Usage
|
25
|
+
------
|
26
|
+
|
27
|
+
$ timer.rb [duration]
|
28
|
+
|
29
|
+
As in:
|
30
|
+
|
31
|
+
$ timer.rb 2h
|
32
|
+
$ timer.rb 2m
|
33
|
+
$ timer.rb 2s
|
34
|
+
$ timer.rb 2h 3m
|
35
|
+
$ timer.rb 0.5h
|
36
|
+
|
37
|
+
Bugs/Contact
|
38
|
+
------------
|
39
|
+
|
40
|
+
Got a problem? Create an issue in the [Github Tracker](https://github.com/febuiles/timer.rb/issues).
|
41
|
+
|
42
|
+
Author
|
43
|
+
------
|
44
|
+
Federico Builes - federico@mheroin.com - @febuiles
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Empty Rakefile...
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
file_list = FileList['spec/*_spec.rb']
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
7
|
+
t.pattern = file_list
|
8
|
+
t.rspec_opts = ["--colour", "--format progress"]
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Default: run specs.'
|
12
|
+
task :default => 'spec'
|
13
|
+
|
data/bin/foo.rb
ADDED
data/bin/timer.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems
|
2
|
+
|
3
|
+
require "timer"
|
4
|
+
|
5
|
+
def usage
|
6
|
+
puts "Usage: timer.rb [duration]\n\n"
|
7
|
+
puts "Examples: timer.rb 2h"
|
8
|
+
puts "\t timer.rb 2s"
|
9
|
+
puts "\t timer.rb 2m"
|
10
|
+
puts "\t timer.rb 2m 2h 2s\n\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
duration = Timer::TimeParser.parse_duration(ARGV)
|
14
|
+
duration.nil? ? usage : Timer::Timer.new(duration)
|
15
|
+
|
data/lib/timer.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Timer
|
2
|
+
module TimeParser
|
3
|
+
def self.parse_duration(duration)
|
4
|
+
return nil if duration.nil?
|
5
|
+
|
6
|
+
total = 0
|
7
|
+
hours = []
|
8
|
+
mins = []
|
9
|
+
secs = []
|
10
|
+
|
11
|
+
# split only if we receive a string, ignore on arrays.
|
12
|
+
if duration.respond_to?(:split)
|
13
|
+
time_chunks = duration.split(" ")
|
14
|
+
else
|
15
|
+
time_chunks = duration
|
16
|
+
end
|
17
|
+
|
18
|
+
time_chunks.reject! { |c| c !~ /\d+[mhs]$/ }
|
19
|
+
hours += time_chunks.select {|c| c[-1,1] == "h" }
|
20
|
+
mins += time_chunks.select {|c| c[-1,1] == "m" }
|
21
|
+
secs += time_chunks.select {|c| c[-1,1] == "s" }
|
22
|
+
|
23
|
+
total += hours.inject(0) { |sum, x| sum + (x.to_i * 3600) }
|
24
|
+
total += mins.inject(0) { |sum, x| sum + (x.to_i * 60) }
|
25
|
+
total += secs.inject(0) { |sum, x| sum + x.to_i }
|
26
|
+
|
27
|
+
# nil otherwise
|
28
|
+
total unless total == 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
data/lib/timer/timer.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timer.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Federico Builes
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-06 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |+
|
35
|
+
Use:
|
36
|
+
|
37
|
+
$ timer.rb [duration]
|
38
|
+
|
39
|
+
As in:
|
40
|
+
|
41
|
+
$ timer.rb 2h
|
42
|
+
$ timer.rb 2m
|
43
|
+
$ timer.rb 2h 3m
|
44
|
+
$ timer.rb 0.5h
|
45
|
+
|
46
|
+
email: federico.builes@gmail.com
|
47
|
+
executables:
|
48
|
+
- timer.rb
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- README.markdown
|
55
|
+
- Rakefile
|
56
|
+
- LICENSE
|
57
|
+
- lib/timer/time_parser.rb
|
58
|
+
- lib/timer/timer.rb
|
59
|
+
- lib/timer/version.rb
|
60
|
+
- lib/timer.rb
|
61
|
+
- bin/foo.rb
|
62
|
+
- bin/timer.rb
|
63
|
+
has_rdoc: false
|
64
|
+
homepage: http://github.com/febuiles/timer.rb
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.7
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Command-line timer
|
97
|
+
test_files: []
|
98
|
+
|