danno_ball_clock 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -0
  3. data/lib/clock.rb +11 -18
  4. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc2c82de3913f0338c99b7db8770083ecc6e0682
4
- data.tar.gz: 121c079f5a33de62946c2497a39791ae6e9a132a
3
+ metadata.gz: 490bcfa18da3ea07e32bfb3907bf213898e707e6
4
+ data.tar.gz: 9c8e42b0f737d9b33d24bb2a8d10fd7a92ef0159
5
5
  SHA512:
6
- metadata.gz: 54beb244fd87d7da5425a12904fcee3e9765724b52a7a2031bd33ab56a8b6eecce9d3bd0269fc6979461bed9707d7bdb860dbf088eeeb0243c05e342c6f5f87b
7
- data.tar.gz: 1ffe67f6d97ba834f284645297d38ef3b344409e40f7d861554edf5f87ed5ffea6d653777915c5406fb3a934bacbbfcf86278078314d26a1e228aa615bbbf651
6
+ metadata.gz: ec8e7476e9e2abb05d486e62de25d5f8138af99fafea5c7bac5bf9bc8cfd2cac9a1f4f9a2ed9fe46ea8b6f94081a09f3c7a4d7e6ab4e91b003916f080e883fcb
7
+ data.tar.gz: 5faf2433c90b3906c59be94b1547eab1d4a11a9b1a1d5bdc55f5808487747491c92c2bbb8ab9da5579eb1dcb08fba5f40b8a1dedc228226342e87f11126da6da
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ ____ ___ ____ ____ __ __ ______
2
+ | _ \ / _ \ | \ / \ | | | | / 12 \
3
+ | | | | | | | | | [] / / ^ \ | | | | | ^ |
4
+ | |_| | | |_| | | [] \ / /\ \ | |__ | |__ |9 |-> 3|
5
+ |____/[] \ ___ /[] |____/ /__ / \ __\ |_____| |_____| \___6__/
6
+
7
+ Movement has long been used to measure time. For example, the ball clock is a simple device which keeps track of the passing minutes by moving ball-bearings. Each minute, a rotating arm removes a ball bearing from the queue at the bottom, raises it to the top of the clock and deposits it on a track leading to indicators displaying minutes, five-minutes and hours. These indicators display the time between 1:00 and 12:59, but without 'a.m.' or 'p.m.' indicators. Thus 2 balls in the minute indicator, 6 balls in the five-minute indicator and 5 balls in the hour indicator displays the time 5:32.
8
+
9
+ # Requirements
10
+ __ __ _ ____ ___ ___ \\ //
11
+ | \_/ | / \ / __| / \ \\ || \\//
12
+ | | / _ \ | |__ | [ ] | \\ //\\
13
+ |_/\_/\_| /_/ \_\ \____| \___/ ||_\\ // \\
14
+
15
+ * Ruby -v 2.2.0+ # Use Rvm where possible `rvm install version_number`
16
+ * Install the clock `gem install danno_ball_clock` or clone it from this repo.
17
+
18
+
19
+ # INFO
20
+
21
+ Valid numbers are in the range 27 to 127.
22
+
23
+ The Clock supports two modes of computation.
24
+
25
+ The Clock takes two parameters, the number of balls and the number of minutes to run the Clock for. If the number of minutes is specified, the clock runs the number of minutes and reports the state of the tracks at that point in a JSON format. If no run time is provided then a JSON format will be returned with the number of days tell ball queue order returns to it's original state.
26
+
27
+ Sample Input
28
+ 30 325
29
+
30
+ Output for the Sample Input
31
+ {"Min":[],"FiveMin":[22,13,25,3,7],"Hour":[6,12,17,4,15],"Main"
32
+ [11,5,26,18,2,30,19,8,24,10,29,20,16,21,28,1,23,14,27,9],"cycleDays":0}
33
+
34
+ # Using the Gem!
35
+
36
+ * `ruby -Ilib ./bin/clock {27,0}` or `ruby -Ilib ./bin/clock {30,325}` # if cloned
37
+ * `ruby -Ilib ~/.rvm/gems/ruby-2.2.3/gems/danno_ball_clock-0.0.0/bin/clock {33,90}` # if installed via `gem install`
38
+
39
+
data/lib/clock.rb CHANGED
@@ -10,7 +10,7 @@ class Clock
10
10
  ###
11
11
  # @method add_minute adds a ball from the begining of the main
12
12
  # queue to the minute track. Once the minute track is full
13
- # the ball will drop to the five minute track triggering in
13
+ # the ball will drop to the five minute track triggering in
14
14
  # reverse order the minute track to deposit to the main queue.
15
15
  # When the five minute track is full it will pass the next ball from
16
16
  # from the main queue to the hour track which triggers the five min
@@ -22,27 +22,21 @@ class Clock
22
22
  @min_track << @current_que.shift
23
23
  elsif @five_min_track.length < 11
24
24
  @five_min_track << @current_que.shift
25
- reverse_track = @min_track.reverse
26
- @current_que.concat(reverse_track)
25
+ @current_que.concat(@min_track.reverse)
27
26
  @min_track = []
28
27
  elsif @hour_track.length < 11
29
28
  @hour_track << @current_que.shift
30
- reverse_track = @min_track.reverse
31
- @current_que.concat(reverse_track)
29
+ @current_que.concat(@min_track.reverse)
32
30
  @min_track = []
33
- reverse_five_min_track = @five_min_track.reverse
34
- @current_que.concat(reverse_five_min_track)
31
+ @current_que.concat(@five_min_track.reverse)
35
32
  @five_min_track = []
36
33
  else
37
34
  que_ball = @current_que.shift
38
- reverse_track = @min_track.reverse
39
- @current_que.concat(reverse_track)
35
+ @current_que.concat(@min_track.reverse)
40
36
  @min_track = []
41
- reverse_five_min_track = @five_min_track.reverse
42
- @current_que.concat(reverse_five_min_track)
37
+ @current_que.concat(@five_min_track.reverse)
43
38
  @five_min_track = []
44
- reverse_hour_track = @hour_track.reverse
45
- @current_que.concat(reverse_hour_track)
39
+ @current_que.concat(@hour_track.reverse)
46
40
  @current_que << que_ball
47
41
  @hour_track = []
48
42
  @hours_passed += 12
@@ -50,13 +44,13 @@ class Clock
50
44
  if @current_que == @start_order
51
45
  @repeat = true
52
46
  end
53
- end
47
+ end
54
48
  end
55
49
 
56
50
  ###
57
51
  # @param [Fixnum, Fixnum] runs clock with number of balls to start with and optionally a runtime.
58
52
  # @return [Json] json hash for min, five_min, hour and main queues. If no runtime
59
- # is provided will calculate days tell que repeats.
53
+ # is provided it will calculate the days tell the que repeats.
60
54
  ###
61
55
  def self.run_ball_clock(balls, run_time)
62
56
  @current_que = []
@@ -82,9 +76,8 @@ class Clock
82
76
  add_minute
83
77
  min_left -= 1
84
78
  end
85
- json_clock = { min: @min_track, fiveMin: @five_min_track, hour: @hour_track, main: @current_que}
86
- result = JSON.generate(json_clock)
79
+ json_clock = { min: @min_track, fiveMin: @five_min_track, hour: @hour_track, main: @current_que }
87
80
  end
88
- result
81
+ JSON.generate(json_clock)
89
82
  end
90
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danno_ball_clock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danial Oberg
@@ -10,16 +10,17 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple ball clock in ruby. Input the number of balls to start with
14
- and optionally a run time
13
+ description: A simple ball clock in ruby. Input a number of balls to start with and
14
+ optionally a run time.
15
15
  email: dan@cs1.com
16
16
  executables:
17
17
  - clock
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - lib/clock.rb
21
+ - README.md
22
22
  - bin/clock
23
+ - lib/clock.rb
23
24
  homepage: http://rubygems.org/gems/danno_ball_clock
24
25
  licenses:
25
26
  - MIT
@@ -30,18 +31,19 @@ require_paths:
30
31
  - lib
31
32
  required_ruby_version: !ruby/object:Gem::Requirement
32
33
  requirements:
33
- - - '>='
34
+ - - ">="
34
35
  - !ruby/object:Gem::Version
35
36
  version: '0'
36
37
  required_rubygems_version: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  requirements: []
42
43
  rubyforge_project:
43
- rubygems_version: 2.0.14
44
+ rubygems_version: 2.4.5.1
44
45
  signing_key:
45
46
  specification_version: 4
46
47
  summary: Ball Clock
47
48
  test_files: []
49
+ has_rdoc: