Class: WiFiddler::CLI
- Inherits:
-
Object
- Object
- WiFiddler::CLI
- Defined in:
- lib/wifiddler.rb
Defined Under Namespace
Classes: ArgumentParser, TooManyAttempts
Constant Summary collapse
- STEP_DOWN_RATE =
1.5
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CLI
Returns a new instance of CLI.
22 23 24 |
# File 'lib/wifiddler.rb', line 22 def initialize( = {}) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/wifiddler.rb', line 11 def @options end |
Class Method Details
.run(io, arguments) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/wifiddler.rb', line 13 def self.run(io, arguments) = { io: io } .merge! ArgumentParser.new.parse(arguments) self.new().run rescue ArgumentParser::InvalidOption => e io.puts e 1 end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wifiddler.rb', line 26 def run Timeout::timeout([:timeout]) do wait_time = [:interval] attempts = 0 until network raise TooManyAttempts if attempts > [:attempts] cycle_airport print '.' attempts += 1 sleep wait_time wait_time *= STEP_DOWN_RATE end end self.io.puts "\nConnected to '#{network}'" 0 rescue TooManyAttempts self.io.puts "\nUnable to establish connection after #{[:attempts]} attempts" 1 rescue Timeout::Error self.io.puts "\nUnable to establish connection after #{[:timeout]} seconds" 1 end |