Class: TTY::Markdown::Symbols Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/markdown/symbols.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 storing the symbols configuration

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbols) ⇒ Symbols

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

Create a TTY::Markdown::Symbols instance

Parameters:

  • symbols (Hash{Symbol => String})

    the symbols configuration



253
254
255
# File 'lib/tty/markdown/symbols.rb', line 253

def initialize(symbols)
  @symbols = symbols
end

Class Method Details

.from(symbols) ⇒ TTY::Markdown::Symbols

Create a TTY::Markdown::Symbols instance

Examples:

symbols = TTY::Markdown::Symbols.from(:ascii)
symbols = TTY::Markdown::Symbols.from({
  base: :ascii,
  override: {
    arrow: "=>"
  }
})

Parameters:

  • symbols (Hash, String, Symbol)

    the symbols configuration

Returns:

Raises:



129
130
131
# File 'lib/tty/markdown/symbols.rb', line 129

def self.from(symbols)
  new(validate_names(build_symbols(symbols)))
end

Instance Method Details

#[](name) ⇒ String?

Retrieve a symbol by name

Examples:

symbols[:arrow]

Parameters:

  • name (Symbol)

    the symbol name

Returns:

  • (String, nil)


269
270
271
# File 'lib/tty/markdown/symbols.rb', line 269

def [](name)
  @symbols[name.to_sym]
end

#wrap_in_brackets(content) ⇒ String

Wrap the content in brackets

Examples:

symbols.wrap_in_brackets("TTY Toolkit")

Parameters:

  • content (String)

    the content

Returns:

  • (String)


284
285
286
# File 'lib/tty/markdown/symbols.rb', line 284

def wrap_in_brackets(content)
  "#{self[:bracket_left]}#{content}#{self[:bracket_right]}"
end

#wrap_in_parentheses(content) ⇒ String

Wrap the content in parentheses

Examples:

symbols.wrap_in_parentheses("TTY Toolkit")

Parameters:

  • content (String)

    the content

Returns:

  • (String)


299
300
301
# File 'lib/tty/markdown/symbols.rb', line 299

def wrap_in_parentheses(content)
  "#{self[:paren_left]}#{content}#{self[:paren_right]}"
end