rubiks-cli 1.3.0 → 1.4.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 +4 -4
- data/bin/rubiks +54 -19
- data/lib/rubiks_cli/clear.rb +1 -1
- data/lib/rubiks_cli/loop/action.rb +19 -0
- data/lib/rubiks_cli/loop/builder.rb +16 -0
- data/lib/rubiks_cli/loop/engine.rb +40 -0
- data/lib/rubiks_cli/timer.rb +1 -1
- data/lib/rubiks_cli/version.rb +1 -1
- data/lib/rubiks_cli.rb +3 -2
- metadata +4 -3
- data/lib/rubiks_cli/help.rb +0 -9
- data/lib/rubiks_cli/solve.rb +0 -49
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b01173da4ddca951dac1a67a9d4eb4a872162ffebd3751fc89d30b5512128eb0
|
|
4
|
+
data.tar.gz: fd61a5af3f725ad9d042514ba252ab206ad3ffce7758acc709c58f68ace07a69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 288fa531855f4e33f79bf991893019614068ac46f314a250f812124927fe1752c4f4ba0544f28061014e53632c9541970c49a3007e9ec58e6d32c048ebed483e
|
|
7
|
+
data.tar.gz: 79dfc148a7ffbe9292942346f51585f6560f45c1f2b7ed1c7dc766c3e828b9e2d043264af70cb61235b6e4a081fc54eb8b10835217743d18684589704c78f64c
|
data/bin/rubiks
CHANGED
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
require 'optparse'
|
|
3
3
|
require 'rubiks_cli'
|
|
4
4
|
|
|
5
|
-
options = {
|
|
6
|
-
|
|
7
|
-
inspection: false,
|
|
8
|
-
loop: true,
|
|
9
|
-
scramble: false,
|
|
10
|
-
time: false,
|
|
11
|
-
wipe: false,
|
|
12
|
-
}
|
|
5
|
+
options = {}
|
|
6
|
+
|
|
13
7
|
OptionParser.new do |opts|
|
|
14
8
|
opts.banner = "Usage: rubiks [options]"
|
|
15
9
|
|
|
@@ -33,21 +27,62 @@ OptionParser.new do |opts|
|
|
|
33
27
|
options[:time] = true
|
|
34
28
|
end
|
|
35
29
|
|
|
36
|
-
opts.on("-w", "--wipe", "Wipe output each loop iteration") do
|
|
37
|
-
options[:wipe] = true
|
|
38
|
-
end
|
|
39
|
-
|
|
40
30
|
end.parse!
|
|
41
31
|
|
|
32
|
+
if options.values.none?
|
|
33
|
+
options[:scramble] = true
|
|
34
|
+
options[:time] = true
|
|
35
|
+
end
|
|
36
|
+
|
|
42
37
|
RubiksCli::Clear.screen if options[:clear]
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
puts RubiksCli::Scrambler.get_scramble
|
|
48
|
-
elsif options[:time]
|
|
39
|
+
output_scramble = lambda { puts RubiksCli::Scrambler.get_scramble }
|
|
40
|
+
start_timer = lambda { RubiksCli::Timer.start(options[:inspection]) }
|
|
41
|
+
start_timer_then_output_scramble = lambda {
|
|
49
42
|
RubiksCli::Timer.start(options[:inspection])
|
|
43
|
+
puts "\n#{RubiksCli::Scrambler.get_scramble}"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if options[:loop]
|
|
47
|
+
|
|
48
|
+
if options[:time] && options[:scramble]
|
|
49
|
+
RubiksCli::Clear.screen
|
|
50
|
+
RubiksCli::Loop.build(
|
|
51
|
+
RubiksCli::Loop.create_action('', start_timer_then_output_scramble, "start solve"),
|
|
52
|
+
[ RubiksCli::Loop.create_action('n', output_scramble, "generate new scramble"), ]
|
|
53
|
+
).start
|
|
54
|
+
|
|
55
|
+
elsif options[:scramble]
|
|
56
|
+
RubiksCli::Clear.screen
|
|
57
|
+
RubiksCli::Loop.build(
|
|
58
|
+
RubiksCli::Loop.create_action('', output_scramble, "generate a scramble"),
|
|
59
|
+
[ RubiksCli::Loop.create_action('t', start_timer_then_output_scramble, "start timer"), ]
|
|
60
|
+
).start
|
|
61
|
+
|
|
62
|
+
elsif options[:time]
|
|
63
|
+
RubiksCli::Clear.screen
|
|
64
|
+
RubiksCli::Loop.build(
|
|
65
|
+
RubiksCli::Loop.create_action('', start_timer, "start timer"),
|
|
66
|
+
[ RubiksCli::Loop.create_action('n', output_scramble, "generate a scramble"), ]
|
|
67
|
+
).start
|
|
68
|
+
|
|
69
|
+
else
|
|
70
|
+
puts "Invalid options for loop mode: must specify --time and/or --scramble"
|
|
71
|
+
end
|
|
50
72
|
else
|
|
51
|
-
|
|
52
|
-
|
|
73
|
+
if options[:time] && options[:scramble]
|
|
74
|
+
output_scramble.call
|
|
75
|
+
gets
|
|
76
|
+
RubiksCli::Clear.line_above
|
|
77
|
+
start_timer.call
|
|
78
|
+
|
|
79
|
+
elsif options[:scramble]
|
|
80
|
+
output_scramble.call
|
|
81
|
+
|
|
82
|
+
elsif options[:time]
|
|
83
|
+
start_timer.call
|
|
84
|
+
|
|
85
|
+
else
|
|
86
|
+
end
|
|
87
|
+
|
|
53
88
|
end
|
data/lib/rubiks_cli/clear.rb
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require_relative '../clear'
|
|
2
|
+
|
|
3
|
+
module RubiksCli
|
|
4
|
+
module Loop
|
|
5
|
+
class Action < Data.define(:command, :function, :help)
|
|
6
|
+
private_class_method :new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.create_action(command, function, description)
|
|
10
|
+
help = "Press '#{command}' to #{description}"
|
|
11
|
+
Action.send(:new, command, function, help)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
DEFAULT_ACTIONS = [
|
|
15
|
+
create_action('c', RubiksCli::Clear.method(:screen), 'clear the screen'),
|
|
16
|
+
create_action('q', lambda { raise SystemExit }, 'quit'),
|
|
17
|
+
]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative 'action'
|
|
2
|
+
require_relative 'engine'
|
|
3
|
+
|
|
4
|
+
module RubiksCli
|
|
5
|
+
module Loop
|
|
6
|
+
private
|
|
7
|
+
def self.build_help_message(actions)
|
|
8
|
+
actions.map { |action| action.help }.join("\n")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.build(on_enter, actions)
|
|
12
|
+
help_action = create_action('h', -> { puts build_help_message(actions) }, "show this message")
|
|
13
|
+
Loop::Engine.send(:new, on_enter, actions += DEFAULT_ACTIONS << help_action)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require_relative '../clear'
|
|
2
|
+
|
|
3
|
+
module RubiksCli
|
|
4
|
+
module Loop
|
|
5
|
+
class Engine
|
|
6
|
+
private_class_method :new
|
|
7
|
+
|
|
8
|
+
def initialize(action_on_enter, other_actions)
|
|
9
|
+
commands = other_actions.map { |action| action.command }
|
|
10
|
+
if commands.uniq.size != commands.size
|
|
11
|
+
raise ArgumentError, "Duplicate command"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@actions = Hash.new(action_on_enter.function)
|
|
15
|
+
other_actions.each { |action| @actions[action.command] = action.function }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def start
|
|
19
|
+
@actions['h'].call
|
|
20
|
+
loop do
|
|
21
|
+
input = gets.chomp.downcase
|
|
22
|
+
Clear.line_above
|
|
23
|
+
@actions[input].call
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if __FILE__ == $0
|
|
31
|
+
require_relative 'builder'
|
|
32
|
+
|
|
33
|
+
on_enter = lambda { puts "You pressed Enter!" }
|
|
34
|
+
actions = [
|
|
35
|
+
RubiksCli::Loop.build_action('x', -> { puts "Action X executed" }, "execute action X"),
|
|
36
|
+
RubiksCli::Loop.build_action('y', -> { puts "Action Y executed" }, "execute action Y"),
|
|
37
|
+
]
|
|
38
|
+
loop_instance = RubiksCli::Loop.build_loop(on_enter, actions)
|
|
39
|
+
loop_instance.start
|
|
40
|
+
end
|
data/lib/rubiks_cli/timer.rb
CHANGED
data/lib/rubiks_cli/version.rb
CHANGED
data/lib/rubiks_cli.rb
CHANGED
|
@@ -2,8 +2,9 @@ require_relative "rubiks_cli/version"
|
|
|
2
2
|
require_relative "rubiks_cli/scrambler"
|
|
3
3
|
require_relative "rubiks_cli/timer"
|
|
4
4
|
require_relative "rubiks_cli/clear"
|
|
5
|
-
require_relative "rubiks_cli/
|
|
6
|
-
require_relative "rubiks_cli/
|
|
5
|
+
require_relative "rubiks_cli/loop/builder"
|
|
6
|
+
require_relative "rubiks_cli/loop/action"
|
|
7
|
+
require_relative "rubiks_cli/loop/engine"
|
|
7
8
|
|
|
8
9
|
module RubiksCli
|
|
9
10
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubiks-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Noah Scott
|
|
@@ -23,9 +23,10 @@ files:
|
|
|
23
23
|
- bin/rubiks
|
|
24
24
|
- lib/rubiks_cli.rb
|
|
25
25
|
- lib/rubiks_cli/clear.rb
|
|
26
|
-
- lib/rubiks_cli/
|
|
26
|
+
- lib/rubiks_cli/loop/action.rb
|
|
27
|
+
- lib/rubiks_cli/loop/builder.rb
|
|
28
|
+
- lib/rubiks_cli/loop/engine.rb
|
|
27
29
|
- lib/rubiks_cli/scrambler.rb
|
|
28
|
-
- lib/rubiks_cli/solve.rb
|
|
29
30
|
- lib/rubiks_cli/timer.rb
|
|
30
31
|
- lib/rubiks_cli/version.rb
|
|
31
32
|
- rubiks-cli.gemspec
|
data/lib/rubiks_cli/help.rb
DELETED
data/lib/rubiks_cli/solve.rb
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
require_relative 'clear'
|
|
2
|
-
require_relative 'help'
|
|
3
|
-
require_relative 'timer'
|
|
4
|
-
require_relative 'scrambler'
|
|
5
|
-
|
|
6
|
-
module RubiksCli
|
|
7
|
-
class Solve
|
|
8
|
-
def self.solve(inspection)
|
|
9
|
-
puts Scrambler.get_scramble
|
|
10
|
-
gets
|
|
11
|
-
Clear.line_above
|
|
12
|
-
Timer.start(inspection)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.loop(clear_screen, inspection)
|
|
16
|
-
Help.loop
|
|
17
|
-
Kernel.loop do
|
|
18
|
-
begin
|
|
19
|
-
input = gets.chomp
|
|
20
|
-
clear_screen ? Clear.screen : Clear.line_above
|
|
21
|
-
process_input(input, inspection)
|
|
22
|
-
rescue SystemExit
|
|
23
|
-
exit
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
def self.process_input(cmd, inspection)
|
|
30
|
-
case cmd.downcase
|
|
31
|
-
when 'n'
|
|
32
|
-
puts Scrambler.get_scramble
|
|
33
|
-
when 'c'
|
|
34
|
-
Clear.screen
|
|
35
|
-
when 'h', '?'
|
|
36
|
-
Help.loop
|
|
37
|
-
when 'q'
|
|
38
|
-
raise SystemExit
|
|
39
|
-
else
|
|
40
|
-
Timer.start(inspection)
|
|
41
|
-
puts "\n#{Scrambler.get_scramble}"
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
if __FILE__ == $0
|
|
48
|
-
RubiksCli::Solve.loop(true, false)
|
|
49
|
-
end
|