Class: TTY::Link::PlainLink Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/link/plain_link.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Responsible for converting a URL to a plain terminal link

Instance Method Summary collapse

Constructor Details

#initialize(name, url, template) ⇒ PlainLink

Create a TTY::Link::PlainLink instance

Examples:

plain_link = TTY::Link::PlainLink.new(
  "TTY Toolkit", "https://ttytoolkit.org", ":name (:url)")

Parameters:

  • name (String)

    the URL name

  • url (String)

    the URL target

  • template (String)

    the URL replacement template



31
32
33
34
35
# File 'lib/tty/link/plain_link.rb', line 31

def initialize(name, url, template)
  @name = name
  @url = url
  @template = template
end

Instance Method Details

#to_sString

Convert this link to a plain string

Examples:

plain_link.to_s
# => "TTY Toolkit (https://ttytoolkit.org)"

Returns:

  • (String)


46
47
48
49
# File 'lib/tty/link/plain_link.rb', line 46

def to_s
  replacements = {":name" => @name, ":url" => @url}
  @template.gsub(REPLACEMENT_TOKENS_PATTERN, replacements)
end