Class: Playoffs::Cli
Overview
A very simple list of commands matching ARGV as input. Allows for capturing the output via the passed in IO object used for construction. This class is an example of how the underlying data structures, such as: BestOf, Round, Series, Team, and Tournament, in this library can be used.
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#simulator ⇒ Object
readonly
Returns the value of attribute simulator.
Instance Method Summary collapse
-
#initialize(io, script: 'bin/playoffs', loader: Loader.new, simulator: RandomSimulator.new) ⇒ Cli
constructor
A new instance of Cli.
- #run(args) ⇒ Object
Constructor Details
#initialize(io, script: 'bin/playoffs', loader: Loader.new, simulator: RandomSimulator.new) ⇒ Cli
Returns a new instance of Cli.
32 33 34 35 36 37 |
# File 'lib/playoffs/cli.rb', line 32 def initialize(io, script: 'bin/playoffs', loader: Loader.new, simulator: RandomSimulator.new) @io = io @script = script @loader = loader @simulator = simulator end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
13 14 15 |
# File 'lib/playoffs/cli.rb', line 13 def io @io end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
19 20 21 |
# File 'lib/playoffs/cli.rb', line 19 def loader @loader end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
16 17 18 |
# File 'lib/playoffs/cli.rb', line 16 def script @script end |
#simulator ⇒ Object (readonly)
Returns the value of attribute simulator.
22 23 24 |
# File 'lib/playoffs/cli.rb', line 22 def simulator @simulator end |
Instance Method Details
#run(args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/playoffs/cli.rb', line 40 def run(args) path = args[0].to_s action = args[1].to_s if path.empty? && action.empty? run_help(path, action, args) return self end action = 'bracket' if action.empty? method_name = "run_#{action}" if respond_to?(method_name, true) send(method_name, path, action, args) else io.puts("Unknown: #{action}") end self end |