Class: TTT::Binary::Parser
- Inherits:
-
Object
- Object
- TTT::Binary::Parser
show all
- Defined in:
- lib/ttt/binary.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(binary) ⇒ Parser
Returns a new instance of Parser.
45
46
47
|
# File 'lib/ttt/binary.rb', line 45
def initialize(binary)
self.binary = binary
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
49
50
51
52
|
# File 'lib/ttt/binary.rb', line 49
def method_missing(meth, *args, &block)
super unless binary.respond_to? meth
binary.send meth, *args, &block
end
|
Instance Attribute Details
#binary ⇒ Object
Returns the value of attribute binary.
43
44
45
|
# File 'lib/ttt/binary.rb', line 43
def binary
@binary
end
|
Instance Method Details
#define_banner(options) ⇒ Object
70
71
72
73
|
# File 'lib/ttt/binary.rb', line 70
def define_banner(options)
options.banner = "Usage: ttt --interface interface_name\n" \
"ttt is an implementation of Tic Tac Toe by Josh Cheek\n\n"
end
|
#define_help(options) ⇒ Object
88
89
90
91
92
|
# File 'lib/ttt/binary.rb', line 88
def define_help(options)
options.on '-h', '--help', 'Display this screen' do
fileout.puts options
end
end
|
#define_interface(options) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/ttt/binary.rb', line 75
def define_interface(options)
options.on '-i', '--interface TYPE', "Specify which interface to play on. Select from: #{list_of_registered}" do |interface_name|
if interface_name.equal? true
fileerr.puts "Please supply interface type"
Kernel.exit 1
elsif has_interface? interface_name
interface(interface_name).new(options_for_interface).play
else
fileerr.puts "#{interface_name.inspect} is not a valid interface, select from: #{list_of_registered}"
end
end
end
|
#options ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/ttt/binary.rb', line 58
def options
OptionParser.new do |options|
define_banner options
define_interface options
define_help options
end
end
|
#options_for_interface ⇒ Object
66
67
68
|
# File 'lib/ttt/binary.rb', line 66
def options_for_interface
return :filein => filein, :fileout => fileout, :fileerr => fileerr
end
|
#parse(argv) ⇒ Object
54
55
56
|
# File 'lib/ttt/binary.rb', line 54
def parse(argv)
options.parse argv
end
|