Class: TTY::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/text.rb,
lib/tty/text/wrapping.rb,
lib/tty/text/truncation.rb

Overview

A class responsible for text manipulations

Defined Under Namespace

Classes: Truncation, Wrapping

Constant Summary collapse

SPACE =
" ".freeze
NEWLINE =
"\n".freeze
DEFAULT_WIDTH =
80.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.truncate(text, value) ⇒ Object .truncate(text, value, options) ⇒ Object

Truncate a text at a given length (defaults to 30)

Examples:

truncate("The sovereignest thing on earth is parmacetti for an inward bruise.")
# => "The sovereignest thing on ear…"

truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 20)
# => "The sovereignest th…"

truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 20, separator: ' ' )
# => "The sovereignest…"

truncate("The sovereignest thing on earth is parmacetti for an inward bruise.", length: 40, trailing: '... (see more)' )
# => "The sovereignest thing on... (see more)"

Overloads:

  • .truncate(text, value) ⇒ Object

    truncates text at given value

    Parameters:

    • value (Integer)
  • .truncate(text, value, options) ⇒ Object

    Parameters:

    • value (Integer)
    • options (Hash)

    Options Hash (options):

    • :separator (Symbol)

      the separation character

    • :trailing (Symbol)

      the trailing characters

Parameters:

  • text (String)

    the text to be truncated



80
81
82
# File 'lib/tty/text.rb', line 80

def self.truncate(text, *args)
  Truncation.new(text, *args).truncate
end

.wrap(text, value) ⇒ Object .wrap(text, value, options) ⇒ Object

Wrap a text into lines no longer than provided length

Examples:

wrap("Some longish text", 8)
 # => "Some\nlongish\ntext"

wrap("Some longish text", :length => 8)
 # => "Some\nlongish\ntext"

wrap("Some longish text", 8, :indent => 4)
 # => >    Some
      >    longish
      >    text

Overloads:

  • .wrap(text, value) ⇒ Object

    wraps text at given value

    Parameters:

    • value (Integer)
  • .wrap(text, value, options) ⇒ Object

    Parameters:

    • value (Integer)
    • options (Hash)

    Options Hash (options):

    • :indent (Symbol)

      the indentation

Parameters:

  • text (String)

    the text to be wrapped



46
47
48
# File 'lib/tty/text.rb', line 46

def self.wrap(text, *args)
  Wrapping.new(text, *args).wrap
end

Instance Method Details

#split_modeObject

Specifies the split mode for words



15
16
# File 'lib/tty/text.rb', line 15

def split_mode
end