Module: Warg::Host::Parser

Defined in:
lib/warg.rb

Constant Summary collapse

REGEXP =
URI.regexp("ssh")

Class Method Summary collapse

Class Method Details

.call(host_string) ⇒ Object



699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/warg.rb', line 699

def call(host_string)
  match_data = REGEXP.match("ssh://#{host_string}")

  query_string = match_data[8] || ""
  query_fragments = query_string.split("&")

  properties = query_fragments.inject({}) do |all, fragment|
    name, value = fragment.split("=", 2)
    all.merge!(name.to_sym => value)
  end

  {
    user: match_data[3],
    address: match_data[4],
    port: match_data[5],
    properties: properties
  }
end