ztk 0.0.17 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Jove Labs
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+ require 'benchmark'
21
+
22
+ module ZTK
23
+
24
+ # ZTK::Benchmark Error Class
25
+ #
26
+ # @author Zachary Patten <zachary@jovelabs.net>
27
+ class BenchmarkError < Error; end
28
+
29
+ # Benchmark Class
30
+ #
31
+ # @author Zachary Patten <zachary@jovelabs.net>
32
+ class Benchmark
33
+
34
+ class << self
35
+
36
+ def bench(message=nil, stdout=STDOUT)
37
+ !message.nil? and print("#{message} ")
38
+ mark = ::Benchmark.realtime do
39
+ if message.nil?
40
+ yield
41
+ else
42
+ ZTK::Spinner.spin do
43
+ yield
44
+ end
45
+ end
46
+ end
47
+ !message.nil? and puts("completed in %0.4f seconds.\n" % mark)
48
+
49
+ mark
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
data/lib/ztk/spinner.rb CHANGED
@@ -36,7 +36,7 @@ module ZTK
36
36
 
37
37
  class << self
38
38
 
39
- def spin(stdout=$stdout)
39
+ def spin(stdout=STDOUT)
40
40
  charset = %w( | / - \\ )
41
41
  count = 0
42
42
  spinner = Thread.new do
@@ -44,7 +44,7 @@ module ZTK
44
44
  stdout.print(charset[(count += 1) % charset.length])
45
45
  stdout.print("\b")
46
46
  stdout.respond_to?(:flush) and stdout.flush
47
- sleep(0.25)
47
+ sleep(0.1)
48
48
  end
49
49
  end
50
50
  yield.tap do
data/lib/ztk/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
  ################################################################################
20
20
 
21
21
  module ZTK
22
- VERSION = "0.0.17" unless const_defined?(:VERSION)
22
+ VERSION = "0.1.0" unless const_defined?(:VERSION)
23
23
  end
data/lib/ztk.rb CHANGED
@@ -31,6 +31,7 @@ module ZTK
31
31
  class Error < StandardError; end
32
32
 
33
33
  autoload :Base, 'ztk/base'
34
+ autoload :Benchmark, 'ztk/benchmark'
34
35
  autoload :Command, 'ztk/command'
35
36
  autoload :Config, 'ztk/config'
36
37
  autoload :Logger, 'ztk/logger'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -174,6 +174,7 @@ files:
174
174
  - bin/ztk
175
175
  - lib/ztk.rb
176
176
  - lib/ztk/base.rb
177
+ - lib/ztk/benchmark.rb
177
178
  - lib/ztk/command.rb
178
179
  - lib/ztk/config.rb
179
180
  - lib/ztk/logger.rb