def map_scalar(value)
      uri = begin
              URI.parse(value)
            rescue
              nil
            end
      pair = value.split(':')

      if uri && uri.scheme && uri.host
        # absolute URI with scheme, authority, etc
        uri.host, uri.port = host_and_port(uri.host, uri.port)
        return uri.to_s
      elsif pair.size == 2
        # "host:port" pair; three sub-cases...
        if pair.first =~ ELIDED
          # output only the port
          service = pair.first.gsub(REMOVE_ELIDED, '')
          _, port = host_and_port(service, pair.last)
          return port.to_s
        elsif pair.last =~ ELIDED
          # output only the hostname; resolve the port anyway to ensure that
          # the service is running.
          service = pair.first
          port = pair.last.gsub(REMOVE_ELIDED, '')
          host, = host_and_port(service, port)
          return host
        else
          # output port:hostname pair
          host, port = host_and_port(pair.first, pair.last)
          return "#{host}:#{port}"
        end
      else
        fail BadSubstitution, "Can't understand '#{value}'"
      end
    end
def map_scalar(value)
      uri = begin
              URI.parse(value)
            rescue
              nil
            end
      pair = value.split(':')

      if uri && uri.scheme && uri.host
        # absolute URI with scheme, authority, etc
        uri.host, uri.port = host_and_port(uri.host, uri.port)
        return uri.to_s
      elsif pair.size == 2
        # "host:port" pair; three sub-cases...
        if pair.first =~ ELIDED
          # output only the port
          service = pair.first.gsub(REMOVE_ELIDED, '')
          _, port = host_and_port(service, pair.last)
          return port.to_s
        elsif pair.last =~ ELIDED
          # output only the hostname; resolve the port anyway to ensure that
          # the service is running.
          service = pair.first
          port = pair.last.gsub(REMOVE_ELIDED, '')
          host, = host_and_port(service, port)
          return host
        else
          # output port:hostname pair
          host, port = host_and_port(pair.first, pair.last)
          return "#{host}:#{port}"
        end
      else
        fail BadSubstitution, "Can't understand '#{value}'"
      end
    end
Map a single string, replacing service names with IPs and container ports
 with the host ports that they have been mapped to.
 @param [String] value
 @return [String]