ScreenTimer 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.2)
11
+ rcov (0.9.10)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.6.4)
27
+ rcov
28
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 opamp
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = ScreenTimer
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to ScreenTimer
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 opamp. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ScreenTimer"
18
+ gem.homepage = "http://github.com/opamp/ScreenTimer"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Timer application}
21
+ gem.description = %Q{This timer can be used timer. It can count up and count down.}
22
+ gem.email = "opampg@gmail.com"
23
+ gem.authors = ["opamp"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "ScreenTimer #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ScreenTimer}
8
+ s.version = "0.3.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{opamp}]
12
+ s.date = %q{2011-08-09}
13
+ s.description = %q{This timer can be used timer. It can count up and count down.}
14
+ s.email = %q{opampg@gmail.com}
15
+ s.executables = [%q{sctimer}]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "ScreenTimer.gemspec",
29
+ "VERSION",
30
+ "bin/sctimer",
31
+ "lib/ScreenTimer.rb",
32
+ "spec/ScreenTimer_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/opamp/ScreenTimer}
36
+ s.licenses = [%q{MIT}]
37
+ s.require_paths = [%q{lib}]
38
+ s.rubygems_version = %q{1.8.6}
39
+ s.summary = %q{Timer application}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_development_dependency(%q<rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_dependency(%q<rcov>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ end
62
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.3
data/bin/sctimer ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ #-*- encoding: utf-8 -*-
3
+ require 'ScreenTimer'
4
+
5
+ mainTimer = ScTimer.new()
6
+
7
+ if mainTimer.countup? == false then
8
+ print %Q{set timer [h/m/s]: }
9
+ begin
10
+ ti = getCount()
11
+ rescue
12
+ puts %Q{Your input is incorrect.}
13
+ exit 1
14
+ end
15
+ print %Q{OK.Count down } + ti.to_s + "[sec]\n"
16
+
17
+ begin
18
+ mainTimer.setcounter(ti.to_i)
19
+ rescue ArgumentError => e
20
+ puts(e)
21
+ puts("ERROR MESSAGE")
22
+ puts(e.message())
23
+ puts("Argument is incorrect")
24
+ exit 1
25
+ end
26
+ sleep 1
27
+ else
28
+ print "OK. Count up\n"
29
+ end
30
+
31
+ mainTimer.count()
32
+
33
+
34
+
@@ -0,0 +1,251 @@
1
+ #-*- encoding: utf-8 -*-
2
+ require 'curses'
3
+
4
+ def secto(s)
5
+ r = {h: 0,m: 0,s: 0}
6
+ loop do
7
+ if s < 60 then
8
+ r[:s] = s
9
+ break
10
+ end
11
+ s = s - 60
12
+ r[:m] += 1
13
+ end
14
+
15
+ loop do
16
+ if r[:m] < 60 then
17
+ break
18
+ end
19
+ r[:m] -= 60
20
+ r[:h] += 1
21
+ end
22
+ return r
23
+ end
24
+
25
+ def getCount()
26
+ ti = STDIN.gets
27
+ if ti[0] !~ /\d/ then
28
+ raise("User input is invalid.")
29
+ end
30
+
31
+ ks = String.new
32
+ hms = {ho: false,mi: false,se: false}
33
+ counttime = 0
34
+ 0.upto(ti.size - 1) do |x|
35
+ if ti[x] =~ /\d/ then
36
+ ks.concat(ti[x])
37
+ else
38
+ if ti[x] =~ /[Hh]/ and hms[:ho] == false then
39
+ counttime += ks.to_i * 60 * 60
40
+ hms[:ho] = true
41
+ ks = ""
42
+ elsif ti[x] =~ /[Hh]/ and hms[:ho] == true then
43
+ raise("User input is invalid.")
44
+ end
45
+
46
+ if ti[x] =~ /[Mm]/ and hms[:mi] == false then
47
+ counttime += ks.to_i * 60
48
+ hms[:mi] = true
49
+ ks = ""
50
+ elsif ti[x] =~ /[Mm]/ and hms[:mi] == true then
51
+ raise("User input is invalid.")
52
+ end
53
+
54
+ if ti[x] =~ /[Ss]/ and hms[:se] == false then
55
+ counttime += ks.to_i
56
+ hms[:se] = true
57
+ ks = ""
58
+ elsif ti[x] =~ /[Ss]/ and hms[:se] == true then
59
+ raise("User input is invalid.")
60
+ end
61
+ end
62
+ end
63
+ if hms[:ho] == false and hms[:mi] == false and hms[:se] == false then
64
+ raise("User input is invalid.")
65
+ end
66
+ return counttime
67
+ end
68
+
69
+
70
+
71
+
72
+ class CursesCounter
73
+ def initialize(countup,counttime)
74
+ if countup == true or countup == false then
75
+ @countup = countup
76
+ else
77
+ raise(ArgumentError,"CursesCounter::initialize argument error.")
78
+ end
79
+
80
+ if countup == false then
81
+ @countt = counttime
82
+ else
83
+ @countt = 0
84
+ end
85
+ Curses::init_screen
86
+ Curses::setpos(0,0)
87
+ if countup == true then
88
+ Curses::addstr("Count UP")
89
+ else
90
+ Curses::addstr("Count Down")
91
+ end
92
+ Curses::refresh
93
+ end
94
+
95
+ def start()
96
+ Curses::noecho
97
+ Curses::noraw
98
+ Curses::crmode
99
+ Curses::setpos(1,0)
100
+ Curses::addstr("Please any key to start.")
101
+ Curses::refresh
102
+ Curses::getch
103
+ Curses::deleteln
104
+ Curses::refresh
105
+ self.timer
106
+ end
107
+
108
+ def timer()
109
+ Curses::standout
110
+ Curses::noraw
111
+
112
+ if @countup == true then
113
+ self.cup()
114
+ else
115
+ self.cdown()
116
+ end
117
+ Curses::beep
118
+ Curses::beep
119
+ Curses::flash
120
+ end
121
+ protected :timer
122
+
123
+ def cup_exit()
124
+ Curses::close_screen()
125
+ print "TOTAL = " + @countt.to_s + "[s]\n"
126
+ h = secto(@countt)
127
+ print h[:h].to_s + "[h] " + h[:m].to_s + "[m] " + h[:s].to_s + "[s]\n"
128
+ exit 0
129
+ end
130
+ protected :cup_exit
131
+
132
+ def cup()
133
+ Curses::setpos(Curses::lines / 2,Curses::cols / 2)
134
+ Signal.trap(:INT){Curses::setpos(Curses::lines,0);Curses::addstr("STOP!!");sleep(1);cup_exit()}
135
+ Signal.trap(:TERM){}
136
+ Signal.trap(:HUP){}
137
+ s,m,h = 0,0,0
138
+ loop do
139
+ Curses::setpos((Curses::lines / 2) + 1,Curses::cols / 2)
140
+ if s % 60 == 0 and s != 0 then
141
+ s = 0
142
+ m += 1
143
+ end
144
+ if m % 60 == 0 and m != 0 then
145
+ m = 0
146
+ h += 1
147
+ end
148
+ Curses::deleteln
149
+ Curses::addstr(h.to_s + " : " + m.to_s + " : " + s.to_s + " || " + @countt.to_s)
150
+ @countt += 1
151
+ s += 1
152
+ Curses::refresh
153
+ sleep 1
154
+ end
155
+ end
156
+ protected :cup
157
+
158
+
159
+ def cdown()
160
+ Signal.trap(:INT){exit(0)}
161
+ Signal.trap(:TERM){}
162
+ Signal.trap(:HUP){}
163
+ r = secto(@countt)
164
+ @countt.downto(0) do |x|
165
+ Curses::setpos((Curses::lines / 2) + 1,Curses::cols / 2)
166
+ Curses::deleteln
167
+ Curses::addstr(r[:h].to_s + ":" + r[:m].to_s + ":" + r[:s].to_s + " || " + x.to_s)
168
+ Curses::refresh
169
+ sleep 1
170
+ #r[:s] -= 1
171
+ if r[:s] == 0 then
172
+ if r[:m] > 0 then
173
+ r[:m] -= 1
174
+ r[:s] = 60
175
+ elsif r[:m] == 0 and r[:h] > 0 then
176
+ r[:h] -= 1
177
+ r[:m] += 59
178
+ r[:s] = 60
179
+ else
180
+ break
181
+ end
182
+ end
183
+ if r[:m] == 0 then
184
+ if r[:h] > 0 then
185
+ r[:h] -= 1
186
+ r[:m] = 60
187
+ else
188
+ break if r[:s] == 0
189
+ end
190
+ end
191
+ r[:s] -= 1
192
+ end
193
+ end
194
+ protected :cdown
195
+
196
+ def timerend()
197
+ Curses::refresh
198
+ Curses::close_screen
199
+ end
200
+ end
201
+
202
+
203
+
204
+
205
+
206
+ class ScTimer
207
+ def initialize()
208
+ @count = 0
209
+ @countup = true
210
+ loop do
211
+ print %Q{Which will you use? [count up(up) / count down(down)]: }
212
+ md = STDIN.gets
213
+ if md =~ /up$/ then
214
+ @countup = true
215
+ break
216
+ elsif md =~ /down$/ then
217
+ @countup = false
218
+ break
219
+ else
220
+ print %Q{\nInvailid value entered.\n}
221
+ print %Q{exit? [y/n]: }
222
+ if STDIN.gets =~ /^y/ then
223
+ exit 0
224
+ end
225
+ end
226
+ end
227
+ end
228
+
229
+ def setcounter(counts)
230
+ if counts.class == Fixnum and counts >= 0 then
231
+ @count = counts
232
+ else
233
+ raise(ArgumentError,"Invailid value.")
234
+ end
235
+ end
236
+ public :setcounter
237
+
238
+ def countup?()
239
+ return @countup
240
+ end
241
+ public :countup?
242
+
243
+ def count()
244
+ ccounter = CursesCounter.new(@countup,@count)
245
+ ccounter.start
246
+ ccounter.timerend
247
+ end
248
+ public :count
249
+
250
+ end
251
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Screentimer" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'ScreenTimer'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ScreenTimer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - opamp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2153569540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2153569540
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2153569060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2153569060
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &2153568580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.6.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2153568580
47
+ - !ruby/object:Gem::Dependency
48
+ name: rcov
49
+ requirement: &2153568100 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2153568100
58
+ description: This timer can be used timer. It can count up and count down.
59
+ email: opampg@gmail.com
60
+ executables:
61
+ - sctimer
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - ScreenTimer.gemspec
75
+ - VERSION
76
+ - bin/sctimer
77
+ - lib/ScreenTimer.rb
78
+ - spec/ScreenTimer_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: http://github.com/opamp/ScreenTimer
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.6
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Timer application
105
+ test_files: []