Class: SSHKit::Host
- Inherits:
-
Object
- Object
- SSHKit::Host
- Defined in:
- lib/sshkit/host.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #eql?(other_host) ⇒ Boolean (also: #==, #equal?)
- #hash ⇒ Object
-
#initialize(host_string) ⇒ Host
constructor
A new instance of Host.
- #to_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(host_string) ⇒ Host
Returns a new instance of Host.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sshkit/host.rb', line 11 def initialize(host_string) suitable_parsers = [ SimpleHostParser, HostWithPortParser, IPv6HostWithPortParser, HostWithUsernameParser, HostWithUsernameAndPortParser ].select do |p| p.suitable?(host_string) end if suitable_parsers.any? suitable_parsers.first.tap do |parser| @username, @hostname, @port = parser.new(host_string).attributes end else raise UnparsableHostStringError, "Cannot parse host string #{host_string}" end end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/sshkit/host.rb', line 7 def hostname @hostname end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/sshkit/host.rb', line 9 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/sshkit/host.rb', line 7 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
7 8 9 |
# File 'lib/sshkit/host.rb', line 7 def username @username end |
Instance Method Details
#eql?(other_host) ⇒ Boolean Also known as: ==, equal?
37 38 39 |
# File 'lib/sshkit/host.rb', line 37 def eql?(other_host) other_host.hash == hash end |
#hash ⇒ Object
33 34 35 |
# File 'lib/sshkit/host.rb', line 33 def hash username.hash ^ hostname.hash ^ port.hash end |
#to_key ⇒ Object
43 44 45 |
# File 'lib/sshkit/host.rb', line 43 def to_key to_s.to_sym end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/sshkit/host.rb', line 47 def to_s sprintf("%s@%s:%d", username, hostname, port) end |