stop_watch 0.1.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe8209e2f9d17a1974938192c6b9c61400bdbb9e
4
- data.tar.gz: 7d307466c4f693ddf7d217144e4d16dc48b9b051
3
+ metadata.gz: 3cfb8e5e7d370de76e18ad38acc1aced7f5b0c51
4
+ data.tar.gz: 2dd5dcc730b28b2002f3701365be8db52ea5dcee
5
5
  SHA512:
6
- metadata.gz: b694f4bd62fdfd806df99d8d22f28fda773ccebc1707f3e26a79cf7d6250a70bb718d5075e914a49ef17efcd1f9b953a0abd0bf17147b272b0626015a210e4ce
7
- data.tar.gz: '087cbda6acb8c30acf94cc0fbbf450ae2ae9bb6a3e9f1c897604c8e979426f7688c8c567f06c56eb8e4234c610ce5cee3d2645236248d55ff2d0d3bbd3929156'
6
+ metadata.gz: e9a443ebab65bcf7ea72d811e508877931bca7750f7966a75a0486389b4e775d76625445bf89e631af57cec0e62cfe1951b1da1d0cd4a4e93c9a30dfb36df227
7
+ data.tar.gz: 34caf65887b7f4b4d646254d028c593b1070c45a5a1a3400689ecabdc5f74ed78eb19bc369d053ce6e2af0aafcc72dcb81c0bcd49d00beb5f2ab8bb187cc241f
data/.codeclimate.yml CHANGED
@@ -9,6 +9,6 @@ engines:
9
9
  enabled: true
10
10
  ratings:
11
11
  paths:
12
- - "**.rb"
12
+ - "lib/stop_watch.rb"
13
13
  exclude_paths:
14
14
  - test/
data/.travis.yml CHANGED
@@ -8,7 +8,7 @@ env:
8
8
  - secure: qXpWydxv6DHMrvGL8WH4wNRY4MTY7KV/x308Y5dHkZCrI7k9UOccvznp69KT3Z+tzYEFDXfUix5wA6pgyVcvrsQyiLSjGcyzHhxJKs1gk0gcxAkmhwHmUP9aiXWUe/mzpj7Uoc2DHwpPTpK1wQ5kV6eV+jzQLuN3nhfNr2sL8b4=
9
9
  addons:
10
10
  code_climate:
11
- repo_token: TODO! UPDATE_THIS!
11
+ repo_token: 1783800b27684868b9e75c23f8d98913b74d26c4b92d7efca86d3b09c5f85bc8
12
12
  script: bundle exec rake test
13
13
  after_success:
14
14
  - bundle exec codeclimate-test-reporter
data/README.md CHANGED
@@ -1,15 +1,12 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/stop_watch.svg)](http://badge.fury.io/rb/stop_watch)
2
2
  [![Code Climate](https://codeclimate.com/github/danielpclark/stop_watch/badges/gpa.svg)](https://codeclimate.com/github/danielpclark/stop_watch)
3
3
  [![Build Status](https://travis-ci.org/danielpclark/stop_watch.svg)](https://travis-ci.org/danielpclark/stop_watch)
4
- [![Test Coverage](https://codeclimate.com/github/danielpclark/stop_watch/badges/coverage.svg)](https://codeclimate.com/github/danielpclark/stop_watch)
5
4
  [![Inline docs](http://inch-ci.org/github/danielpclark/stop_watch.svg?branch=master)](http://inch-ci.org/github/danielpclark/stop_watch)
6
5
  [![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg)](https://saythanks.io/to/danielpclark)
7
6
 
8
7
  # StopWatch
9
8
 
10
- Quick and dirty copy and paste gem from language_cards source to have a stop watch timer available as a gem.
11
-
12
- Lots of TODOs for this gem, they're not even written yet ;-)
9
+ A stop watch timer where you hit `mark` to start the timer and continue to hit `mark` to mark times.
13
10
 
14
11
  ## Installation
15
12
 
@@ -29,7 +26,38 @@ Or install it yourself as:
29
26
 
30
27
  ## Usage
31
28
 
32
- TODO: Write usage instructions here
29
+ ```ruby
30
+ require 'stop_watch'
31
+
32
+ watch = StopWatch::Timer.new
33
+
34
+ watch.mark
35
+ # => 2017-02-24 18:03:43 -0500
36
+
37
+ watch.time?
38
+ # => false
39
+
40
+ watch.mark
41
+ # => [44.973787791]
42
+
43
+ watch.time?
44
+ # => true
45
+
46
+ watch.mark
47
+ # => [44.973787791, 6.39862104]
48
+
49
+ watch.mark
50
+ # => [44.973787791, 6.39862104, 4.238468485]
51
+
52
+ watch.h # human total time
53
+ # => "00:00:55"
54
+
55
+ watch.ha # human average
56
+ # => "18.54 second average"
57
+
58
+ watch.times
59
+ # => [44.973787791, 6.39862104, 4.238468485]
60
+ ```
33
61
 
34
62
  ## Development
35
63
 
@@ -1,3 +1,3 @@
1
1
  module StopWatch
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/stop_watch.rb CHANGED
@@ -1,48 +1,78 @@
1
1
  require "stop_watch/version"
2
2
 
3
+ ##
4
+ # StopWatch
5
+ #
6
+ # Project namespace for StopWatch.
3
7
  module StopWatch
8
+ ##
9
+ # Timer
10
+ #
11
+ # Object that behaves as a stop watch timer.
4
12
  class Timer
5
13
  def initialize
6
14
  @stamps = []
7
15
  @mark = nil
8
16
  end
9
17
 
18
+ # Start & Mark time with this `mark` method.
19
+ #
20
+ # @return [Time, Array<Float>] First time returns Time start. From then on it returns `times` method result. @see #times
10
21
  def mark
11
22
  if @mark
12
- @stamps << -(@mark - (@mark = Time.now))
23
+ times << -(@mark - (@mark = Time.now))
13
24
  else
14
25
  @mark = Time.now
15
26
  end
16
27
  end
17
28
 
29
+ # Boolean check for any times `mark`ed. Must mark atleast twice for this to be true.
30
+ #
31
+ # @return [true,false]
18
32
  def time?
19
33
  !times.empty?
20
34
  end
21
35
 
36
+ # Human display of total time elapsed in hours, minutes, and seconds.
37
+ #
38
+ # @return [String] String of hh:mm:ss
22
39
  def h # human
23
40
  "%02d:%02d:%02d" % [total/3600%24, total/60%60, total%60]
24
41
  end
25
42
 
43
+ # Average of times. If `time?` if false this will raise an error.
44
+ #
45
+ # @return [Float,Error]
26
46
  def average
27
47
  total.fdiv(times.size)
28
48
  end
29
49
 
30
- def ha # human average
31
-
50
+ # Human representation of average seconds per `mark`.
51
+ #
52
+ # @return [String] String representation of average or empty for none.
53
+ def ha
32
54
  "%0.2f second average" % average
33
55
  rescue
34
56
  ""
35
-
36
57
  end
37
58
 
59
+ # A collection of times `mark`ed. Each represented in Float of seconds since the last `mark`.
60
+ #
61
+ # @return [Array<Float>] Returns array of times marked.
38
62
  def times
39
63
  @stamps
40
64
  end
41
65
 
66
+ # Last time `mark`ed.
67
+ #
68
+ # @return [Float,nil] Returns the last time `mark`ed, or else `nil`.
42
69
  def last
43
70
  @stamps.last
44
71
  end
45
72
 
73
+ # Total time accumulated.
74
+ #
75
+ # @return [Integer,Float] Returns total time since start.
46
76
  def total
47
77
  @stamps.inject(0, :+)
48
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stop_watch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
@@ -71,7 +71,6 @@ files:
71
71
  - bin/setup
72
72
  - lib/stop_watch.rb
73
73
  - lib/stop_watch/version.rb
74
- - lib/timer.rb
75
74
  - stop_watch.gemspec
76
75
  homepage: https://github.com/danielpclark/stop_watch
77
76
  licenses:
data/lib/timer.rb DELETED
@@ -1,49 +0,0 @@
1
-
2
- module LanguageCards
3
- class Timer
4
- def initialize
5
- @stamps = []
6
- @mark = nil
7
- end
8
-
9
- def mark
10
- if @mark
11
- @stamps << -(@mark - (@mark = Time.now))
12
- else
13
- @mark = Time.now
14
- end
15
- end
16
-
17
- def time?
18
- !times.empty?
19
- end
20
-
21
- def h # human
22
- "%02d:%02d:%02d" % [total/3600%24, total/60%60, total%60]
23
- end
24
-
25
- def average
26
- total.fdiv(times.size)
27
- end
28
-
29
- def ha # human average
30
-
31
- "%0.2f #{I18n.t('Timer.AverageSeconds')}" % average
32
- rescue
33
- ""
34
-
35
- end
36
-
37
- def times
38
- @stamps
39
- end
40
-
41
- def last
42
- @stamps.last
43
- end
44
-
45
- def total
46
- @stamps.inject(:+) || 0
47
- end
48
- end
49
- end