Class: VisionMate::Telnet
- Inherits:
-
Object
- Object
- VisionMate::Telnet
- Defined in:
- lib/vision_mate/telnet.rb
Defined Under Namespace
Classes: BadHostNameOrPort, CouldNotConnect, TubeReadError
Instance Attribute Summary collapse
-
#telnet_connection ⇒ Object
Returns the value of attribute telnet_connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(telnet_connection) ⇒ Telnet
constructor
A new instance of Telnet.
- #initiate_scan ⇒ Object
- #scan ⇒ Object
Constructor Details
#initialize(telnet_connection) ⇒ Telnet
Returns a new instance of Telnet.
21 22 23 24 |
# File 'lib/vision_mate/telnet.rb', line 21 def initialize(telnet_connection) self.telnet_connection = telnet_connection set_scanner_to_manual end |
Instance Attribute Details
#telnet_connection ⇒ Object
Returns the value of attribute telnet_connection.
5 6 7 |
# File 'lib/vision_mate/telnet.rb', line 5 def telnet_connection @telnet_connection end |
Class Method Details
.connect(host, port, telnet_class = Net::Telnet) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/vision_mate/telnet.rb', line 13 def self.connect(host, port, telnet_class = Net::Telnet) new(telnet_class.new("Host" => host, "Port" => port)) rescue Net::OpenTimeout, Timeout::Error raise CouldNotConnect, "Failed to connect to #{host}:#{port}" rescue SocketError raise BadHostNameOrPort, "Malformed host name or port" end |
Instance Method Details
#initiate_scan ⇒ Object
33 34 35 36 |
# File 'lib/vision_mate/telnet.rb', line 33 def initiate_scan telnet_connection.cmd("String" => "S", "Match" => /OK/) wait_for_data end |
#scan ⇒ Object
26 27 28 29 30 31 |
# File 'lib/vision_mate/telnet.rb', line 26 def scan initiate_scan result = retrieve_data raise TubeReadError, "One or more tubes not read" if result[/No Read/] strip_prefix(result) end |