climer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1815265c9df127e40509416005508ad43aa7fc95
4
+ data.tar.gz: ff96f4313b44a6c327ce9abe7b2b43dc034ed53a
5
+ SHA512:
6
+ metadata.gz: 41a617fb9f1c584d03a9ea418268b06abc11415d5e0218933a203292986cb3e48133523a32e0ac590ba7b05ab9221050c1bdc8f1e45fd3cb2ae663a6868ddcac
7
+ data.tar.gz: c33f1e92e333482383b569f441968a682ae30cf1d6fe1b0c594fa1e36b8dda09bf1fd6e3f255cff26c9559f3f73381b057dce3ae1942155457424da9195ea7f5
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ coverage
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cli_timer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dustin Morrill
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
+ # Climer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'climer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install climer
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,54 @@
1
+ #!/usr/bin/env rake
2
+ def dump_load_path
3
+ puts $LOAD_PATH.join("\n")
4
+ found = nil
5
+ $LOAD_PATH.each do |path|
6
+ if File.exists?(File.join(path,"rspec"))
7
+ puts "Found rspec in #{path}"
8
+ if File.exists?(File.join(path,"rspec","core"))
9
+ puts "Found core"
10
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
11
+ puts "Found rake_task"
12
+ found = path
13
+ else
14
+ puts "!! no rake_task"
15
+ end
16
+ else
17
+ puts "!!! no core"
18
+ end
19
+ end
20
+ end
21
+ if found.nil?
22
+ puts "Didn't find rspec/core/rake_task anywhere"
23
+ else
24
+ puts "Found in #{path}"
25
+ end
26
+ end
27
+ require 'bundler'
28
+
29
+ require 'rake/clean'
30
+ require 'rake/testtask'
31
+
32
+ require 'cucumber'
33
+ require 'cucumber/rake/task'
34
+
35
+ include Rake::DSL
36
+
37
+ Bundler::GemHelper.install_tasks
38
+
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "lib" << 'spec/support'
41
+ t.test_files = FileList['spec/**/*_spec.rb']
42
+ t.verbose = false
43
+ t.warning = false # pry-rescue has a lot of warnings
44
+ end
45
+
46
+
47
+ CUKE_RESULTS = 'results.html'
48
+ CLEAN << CUKE_RESULTS
49
+ Cucumber::Rake::Task.new(:features) do |t|
50
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
51
+ t.fork = false
52
+ end
53
+
54
+ task :default => [:test,:features]
data/bin/climer ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require_relative '../lib/climer.rb'
6
+
7
+ class App
8
+ include Methadone::Main
9
+ include Methadone::CLILogging
10
+
11
+ main do |*time_until_notification|
12
+ time_until_notification.each do |time|
13
+ t = Climer::Timer.alert_in(time)
14
+ sleep(t.time_remaining.total + 5)
15
+ end
16
+ end
17
+
18
+ # supplemental methods here
19
+
20
+ # Declare command-line interface here
21
+
22
+ # description "one line description of your app"
23
+ #
24
+ # Accept flags via:
25
+ # on("--flag VAL","Some flag")
26
+ # options[flag] will contain VAL
27
+ #
28
+ # Specify switches via:
29
+ # on("--[no-]switch","Some switch")
30
+ #
31
+ # Or, just call OptionParser methods on opts
32
+ #
33
+ # Require an argument
34
+ # arg :some_arg
35
+ #
36
+ # # Make an argument optional
37
+ # arg :optional_arg, :optional
38
+
39
+ arg :time_until_notification, :many
40
+
41
+ version Climer::VERSION
42
+
43
+ use_log_level_option
44
+
45
+ go!
46
+ end
data/climer.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'climer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "climer"
8
+ spec.version = Climer::VERSION
9
+ spec.authors = ["Dustin Morrill"]
10
+ spec.email = ["morrill@ualberta.ca"]
11
+ spec.description = %q{Simple CLI timer}
12
+ spec.summary = %q{Simple CLI timer}
13
+ spec.homepage = "https://github.com/dmorrill10/climer"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency 'methadone', '~> 1.3.0'
22
+ spec.add_dependency 'time_distribution'
23
+ spec.add_dependency 'rufus-scheduler'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency 'aruba'
27
+ spec.add_development_dependency 'rake', '~> 0.9.2'
28
+ spec.add_development_dependency 'turn', '~> 0.9'
29
+ spec.add_development_dependency 'minitest', '~> 4.7'
30
+ spec.add_development_dependency 'awesome_print', '~> 1.0'
31
+ spec.add_development_dependency 'pry-rescue', '~> 1.0'
32
+ spec.add_development_dependency 'simplecov', '~> 0.7'
33
+ spec.add_development_dependency 'timecop'
34
+ # spec.add_development_dependency 'mocha', '~> 0.13'
35
+ end
@@ -0,0 +1,32 @@
1
+ Feature: Help documentation
2
+ In order to tell user's how to use this app
3
+ I want to show useful help documentation.
4
+
5
+ Scenario: App just runs and shows help
6
+ When I get help for "climer"
7
+ Then the exit status should be 0
8
+ And the banner should be present
9
+ And the banner should document that this app takes options
10
+ And the following options should be documented:
11
+ |--version|
12
+ |--log-level|
13
+
14
+ # Feature: Shows the time when notifications will go off
15
+ # As a user of this app
16
+ # I want to specify time durations
17
+ # And see the time that notifications will go off after those durations.
18
+
19
+ # Scenario: Shows times when notifications
20
+ # When I run "cli_timer "
21
+ # Then the exit status should be 0
22
+ # And the banner should be present
23
+ # And the banner should document that this app takes options
24
+ # And the following options should be documented:
25
+ # |--version|
26
+ # |--log-level|
27
+
28
+ # Feature: Shows a useful notification message and plays a chime when a timer goes off
29
+ # As a user of this app
30
+ # I want to specify time durations
31
+ # And once those durations have elapsed
32
+ # I want to see a useful notification message and hear a chime
@@ -0,0 +1 @@
1
+ # Put your step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ @announce_cmd = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,29 @@
1
+ require 'time_distribution/smart_duration'
2
+
3
+ module Climer
4
+ module HumanDuration
5
+ refine Time do
6
+ alias_method :old_plus, :+
7
+ alias_method :old_minus, :-
8
+
9
+ def +(other)
10
+ old_plus(
11
+ if other.kind_of?(String)
12
+ TimeDistribution::SmartDuration.parse(other).total || other
13
+ else
14
+ other
15
+ end
16
+ )
17
+ end
18
+ def -(other)
19
+ old_minus(
20
+ if other.kind_of?(String)
21
+ TimeDistribution::SmartDuration.parse(other).total || other
22
+ else
23
+ other
24
+ end
25
+ )
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ require 'rufus-scheduler'
2
+ require 'duration'
3
+ require 'time_distribution/smart_duration'
4
+ require_relative 'human_duration'
5
+ using Climer::HumanDuration
6
+
7
+ module Rufus::Scheduler
8
+ def self.scheduler() @scheduler ||= start_new end
9
+ def self.every(duration)
10
+ job = scheduler.every TimeDistribution::SmartDuration.parse(duration).total do
11
+ yield if block_given?
12
+ end
13
+ end
14
+ def self.at(time)
15
+ job = scheduler.at time do
16
+ yield if block_given?
17
+ end
18
+ end
19
+ end
20
+
21
+ module Climer
22
+ class Timer
23
+ class << self; alias_method :alert_in, :new; end
24
+
25
+ attr_reader :alert_time
26
+
27
+ CARRIAGE_RETURN = "\r"
28
+ def initialize(duration)
29
+ @alert_time = Time.now + duration
30
+ puts "Alert set to activate at #{@alert_time.asctime}"
31
+ print countdown_string
32
+
33
+ countdown_update_interval = '1 second'
34
+ job = Rufus::Scheduler.every countdown_update_interval do
35
+ print "#{CARRIAGE_RETURN}#{countdown_string}"
36
+ end
37
+
38
+ Rufus::Scheduler.at @alert_time do
39
+ Rufus::Scheduler.scheduler.unschedule(
40
+ job.job_id
41
+ )
42
+ sleep TimeDistribution::SmartDuration.parse(countdown_update_interval).total
43
+ puts ''
44
+ puts "ALERT! Timer expired!"
45
+ end
46
+ end
47
+
48
+ def time_remaining
49
+ Duration.new(@alert_time - Time.now)
50
+ end
51
+ def countdown_string
52
+ time_remaining.format('%h:%M:%S')
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Climer
2
+ VERSION = "0.0.1"
3
+ end
data/lib/climer.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative "climer/version"
2
+
3
+ require_relative 'climer/human_duration'
4
+ require_relative 'climer/timer'
5
+
6
+ module Climer
7
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'support/spec_helper'
2
+
3
+ require_relative '../lib/climer/human_duration'
4
+ using Climer::HumanDuration
5
+
6
+ describe 'Climer::HumanDuration' do
7
+ it '#+ given an English formatted time returns a time given an elapsed time' do
8
+ (Time.new(0) + '2 hours').must_equal Time.new(0, 1, 1, 2)
9
+ end
10
+ it '#- given an English formatted time returns a time given an elapsed time' do
11
+ (Time.new(0, 1, 1, 2) - '2 hours').must_equal Time.new(0)
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'minitest/spec'
5
+ require 'minitest/autorun'
6
+
7
+ begin
8
+ require 'turn'
9
+
10
+ Turn.config do |c|
11
+ # use one of output formats:
12
+ # :outline - turn's original case/test outline mode [default]
13
+ # :progress - indicates progress with progress bar
14
+ # :dotted - test/unit's traditional dot-progress mode
15
+ # :pretty - new pretty reporter
16
+ # :marshal - dump output as YAML (normal run mode only)
17
+ # :cue - interactive testing
18
+ c.format = :dotted
19
+ # use humanized test names (works only with :outline format)
20
+ c.natural = true
21
+ end
22
+
23
+ require 'awesome_print'
24
+ module Minitest::Assertions
25
+ def mu_pp(obj)
26
+ obj.awesome_inspect
27
+ end
28
+ end
29
+
30
+ require 'pry-rescue/minitest'
31
+ #require 'mocha/setup'
32
+ rescue LoadError
33
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'support/spec_helper'
2
+ require 'timecop'
3
+
4
+ require_relative '../lib/climer/timer'
5
+
6
+ describe 'Climer::Timer' do
7
+ describe '#alert_in' do
8
+ it 'should show the end time' do
9
+ Timecop.freeze Time.new(0)
10
+ time_at_alert = Time.new(0) + 60*60
11
+ -> { Climer::Timer.alert_in('1 hour') }.must_output(
12
+ "Alert set to activate at #{time_at_alert.asctime}\n" <<
13
+ "1:00:00"
14
+ )
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: climer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dustin Morrill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: methadone
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: time_distribution
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rufus-scheduler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aruba
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: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: turn
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: awesome_print
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-rescue
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '0.7'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '0.7'
167
+ - !ruby/object:Gem::Dependency
168
+ name: timecop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Simple CLI timer
182
+ email:
183
+ - morrill@ualberta.ca
184
+ executables:
185
+ - climer
186
+ extensions: []
187
+ extra_rdoc_files: []
188
+ files:
189
+ - .gitignore
190
+ - Gemfile
191
+ - LICENSE.txt
192
+ - README.md
193
+ - Rakefile
194
+ - bin/climer
195
+ - climer.gemspec
196
+ - features/climer.feature
197
+ - features/step_definitions/cli_timer_steps.rb
198
+ - features/support/env.rb
199
+ - lib/climer.rb
200
+ - lib/climer/human_duration.rb
201
+ - lib/climer/timer.rb
202
+ - lib/climer/version.rb
203
+ - spec/human_duration_spec.rb
204
+ - spec/support/spec_helper.rb
205
+ - spec/timer_spec.rb
206
+ homepage: https://github.com/dmorrill10/climer
207
+ licenses:
208
+ - MIT
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - '>='
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.0.3
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Simple CLI timer
230
+ test_files:
231
+ - features/climer.feature
232
+ - features/step_definitions/cli_timer_steps.rb
233
+ - features/support/env.rb
234
+ - spec/human_duration_spec.rb
235
+ - spec/support/spec_helper.rb
236
+ - spec/timer_spec.rb