timer_cli 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e8a0f5b836635541aca2c2131ddf0eea53b4768
4
+ data.tar.gz: 87b32f435a580c04f45f30b749ef1e75614cd538
5
+ SHA512:
6
+ metadata.gz: edf2f5ebb883ccca5d95c5bb5c8da75b12a5753ee99ac76443abff5c0c26c4d59d05ef6ac76bac97dc94ca46c886ed234fb82fac2d03b58e8a7b8c875016817c
7
+ data.tar.gz: 217d42c203932660bf43fe5c22ad5bd74aa26de5da4ad12773f62fa4c1ff47d2ed3de1fd8b5e735842420d6b9d2381c9ea565d53a5d5f337bb7c621bb550fa5b
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /pkg/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kami
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,43 @@
1
+ # TimerCli
2
+
3
+ TimerCli is a timer that runs on command line interface.
4
+ It notifies you with Growl when time is up.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'timer_cli'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+
22
+ ```
23
+ $ gem install timer_cli
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ You can use `timer_cli` command as follows.
29
+ The available units are `s` (second) and `m` (minute).
30
+
31
+ Following example, you will show a Growl notification after 15 seconds.
32
+
33
+ ```
34
+ $ timer_cli 15s
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/kami30k/timer_cli/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/timer_cli ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'timer_cli'
4
+
5
+ Signal.trap(:INT) { exit }
6
+
7
+ TimerCli::Command.start
@@ -0,0 +1,12 @@
1
+ module TimerCli
2
+ class Command
3
+ class << self
4
+ def start
5
+ params = Parameters.new(ARGV)
6
+
7
+ timer = Timer.new(params.sec)
8
+ timer.run
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'ruby-growl'
2
+
3
+ module TimerCli
4
+ class Notifier
5
+ def initialize(sec)
6
+ @sec = sec
7
+ end
8
+
9
+ def notify
10
+ growl = Growl.new('localhost', 'Timer')
11
+ growl.add_notification('timer')
12
+ growl.notify('timer', 'Timer', "#{@sec} second(s) have passed.")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module TimerCli
2
+ class Parameters
3
+ attr_reader :sec
4
+
5
+ def initialize(params)
6
+ @sec = parse(params[0])
7
+ end
8
+
9
+ private
10
+
11
+ def parse(time)
12
+ if /(?<sec>\d+)(?<variable>[s|m]{1})/ =~ time
13
+ calculate(sec.to_i, variable)
14
+ else
15
+ raise ArgumentError
16
+ end
17
+ end
18
+
19
+ def calculate(sec, variable)
20
+ sec * case variable
21
+ when 's'
22
+ 1
23
+ when 'm'
24
+ 60
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module TimerCli
2
+ class Timer
3
+ def initialize(sec)
4
+ @sec = sec
5
+ end
6
+
7
+ def run
8
+ puts 'Start timer ...'
9
+
10
+ sleep @sec
11
+
12
+ notify
13
+ end
14
+
15
+ private
16
+
17
+ def notify
18
+ notifier = Notifier.new(@sec)
19
+ notifier.notify
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module TimerCli
2
+ VERSION = '0.0.1'
3
+ end
data/lib/timer_cli.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'timer_cli/version'
2
+
3
+ module TimerCli
4
+ autoload :Timer, 'timer_cli/timer'
5
+ autoload :Notifier, 'timer_cli/notifier'
6
+ autoload :Parameters, 'timer_cli/parameters'
7
+ autoload :Command, 'timer_cli/command'
8
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'timer_cli'
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe TimerCli do
4
+ describe TimerCli::Parameters do
5
+ def params(argv)
6
+ TimerCli::Parameters.new([argv])
7
+ end
8
+
9
+ context 'receive a valid parameter' do
10
+ let(:sec) { params('10s').sec }
11
+ let(:sec_2) { params('10m').sec }
12
+
13
+ it 'should return correct second' do
14
+ expect(sec).to eq 10
15
+ expect(sec_2).to eq 600
16
+ end
17
+ end
18
+
19
+ context 'receive a invalid parameter' do
20
+ let(:sec) { params('10h').sec }
21
+
22
+ it 'should raise error' do
23
+ expect { sec } .to raise_error(ArgumentError)
24
+ end
25
+ end
26
+ end
27
+ end
data/timer_cli.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'timer_cli/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'timer_cli'
9
+ spec.version = TimerCli::VERSION
10
+ spec.authors = ['kami']
11
+ spec.email = ['kami30k@gmail.com']
12
+ spec.summary = %q{Timer on CLI notify with Growl.}
13
+ spec.description = %q{Timer on CLI notify with Growl.}
14
+ spec.homepage = 'https://github.com/kami30k/timer_cli'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'ruby-growl'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec'
27
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timer_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-growl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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
+ description: Timer on CLI notify with Growl.
70
+ email:
71
+ - kami30k@gmail.com
72
+ executables:
73
+ - timer_cli
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/timer_cli
85
+ - lib/timer_cli.rb
86
+ - lib/timer_cli/command.rb
87
+ - lib/timer_cli/notifier.rb
88
+ - lib/timer_cli/parameters.rb
89
+ - lib/timer_cli/timer.rb
90
+ - lib/timer_cli/version.rb
91
+ - spec/spec_helper.rb
92
+ - spec/timer_cli_spec.rb
93
+ - timer_cli.gemspec
94
+ homepage: https://github.com/kami30k/timer_cli
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.2.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Timer on CLI notify with Growl.
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ - spec/timer_cli_spec.rb