danno_ball_clock 0.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 +7 -0
- data/bin/clock +4 -0
- data/lib/clock.rb +86 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4505f962e5cf01c3047f0798b982dca2b13c678
|
4
|
+
data.tar.gz: bfba7f8bce1a3bc944748644502e9f030191e3c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dcb54243405216184cc620d5ade71b6843bcb1b66b9e5eec79d18d3e115dc16488a7b9f3b5b1476240754521264c99714359a8db3a5030af77d720a88833343
|
7
|
+
data.tar.gz: 7cef6446ab24a52c6cc68b85f13ce889a05a3a84d3cf8fd8815b5392a23b95e05649a1d10e6ca2e80ff3804ce25474358d9386c5e5749c88aa7f77610fbfa2ce
|
data/bin/clock
ADDED
data/lib/clock.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'json'
|
3
|
+
###
|
4
|
+
# @author Dan Oberg <dan@cs1.com>
|
5
|
+
# @class Clock
|
6
|
+
###
|
7
|
+
class Clock
|
8
|
+
###
|
9
|
+
# @method add_minute
|
10
|
+
###
|
11
|
+
def self.add_minute
|
12
|
+
if @min_track.length < 4
|
13
|
+
@min_track << @current_que.shift
|
14
|
+
elsif @five_min_track.length < 11
|
15
|
+
@five_min_track << @current_que.shift
|
16
|
+
reverse_track = @min_track.reverse
|
17
|
+
@current_que.concat(reverse_track)
|
18
|
+
@min_track = []
|
19
|
+
elsif @hour_track.length < 11
|
20
|
+
@hour_track << @current_que.shift
|
21
|
+
reverse_track = @min_track.reverse
|
22
|
+
@current_que.concat(reverse_track)
|
23
|
+
@min_track = []
|
24
|
+
reverse_five_min_track = @five_min_track.reverse
|
25
|
+
@current_que.concat(reverse_five_min_track)
|
26
|
+
@five_min_track = []
|
27
|
+
else
|
28
|
+
que_ball = @current_que.shift
|
29
|
+
reverse_track = @min_track.reverse
|
30
|
+
@current_que.concat(reverse_track)
|
31
|
+
@min_track = []
|
32
|
+
reverse_five_min_track = @five_min_track.reverse
|
33
|
+
@current_que.concat(reverse_five_min_track)
|
34
|
+
@five_min_track = []
|
35
|
+
reverse_hour_track = @hour_track.reverse
|
36
|
+
@current_que.concat(reverse_hour_track)
|
37
|
+
@current_que << que_ball
|
38
|
+
@hour_track = []
|
39
|
+
@hours_passed += 12
|
40
|
+
@cycle_days = @hours_passed / 24
|
41
|
+
if @current_que == @start_order
|
42
|
+
@repeat = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
###
|
48
|
+
# @param [Fixnum, Fixnum] runs clock with number of balls and optionally a runtime.
|
49
|
+
# @return [Json] json hash for min, five_min, hour and main queues. If no runtime
|
50
|
+
# is provided will calculate days tell que repeats.
|
51
|
+
###
|
52
|
+
def self.run_ball_clock(balls, run_time)
|
53
|
+
@min = []
|
54
|
+
@five_min = []
|
55
|
+
@hour = []
|
56
|
+
@main = []
|
57
|
+
@result = []
|
58
|
+
@current_que = []
|
59
|
+
@hours_passed = '0'.to_i
|
60
|
+
@repeat = false
|
61
|
+
min_left = run_time.to_i
|
62
|
+
@start_order = Array.new(balls.to_i) { |i| i + 1 }
|
63
|
+
@start_order.freeze
|
64
|
+
@min_track = []
|
65
|
+
@five_min_track = []
|
66
|
+
@hour_track = []
|
67
|
+
que_balls = @start_order.clone
|
68
|
+
que_balls.each do |ball|
|
69
|
+
@current_que << ball
|
70
|
+
end
|
71
|
+
if run_time.to_i == 0 || nil
|
72
|
+
until @repeat == true
|
73
|
+
add_minute
|
74
|
+
end
|
75
|
+
result = puts "Clock cycles in: #{@cycle_days} day\(s\)\."
|
76
|
+
else
|
77
|
+
until min_left == 0
|
78
|
+
add_minute
|
79
|
+
min_left -= 1
|
80
|
+
end
|
81
|
+
json_clock = { min: @min_track, fiveMin: @five_min_track, hour: @hour_track, main: @current_que}
|
82
|
+
result = JSON.generate(json_clock)
|
83
|
+
end
|
84
|
+
result
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: danno_ball_clock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danial Oberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple ball clock in ruby. Input number of ball to start and a optional
|
14
|
+
run time
|
15
|
+
email: dan@cs1.com
|
16
|
+
executables:
|
17
|
+
- clock
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/clock.rb
|
22
|
+
- bin/clock
|
23
|
+
homepage: http://rubygems.org/gems/danno_ball_clock
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.0.14
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Ball Clock
|
47
|
+
test_files: []
|