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



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/warg.rb', line 672

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