Class: Toys::WrappableString

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/wrappable_string.rb

Overview

Defined in the toys-core gem

A string intended for word-wrapped display.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = "") ⇒ WrappableString

Create a wrapped string.

Parameters:

  • string (String, Array<String>) (defaults to: "")

    The string or array of string fragments



13
14
15
# File 'core-docs/toys/wrappable_string.rb', line 13

def initialize(string = "")
  # Source available in the toys-core gem
end

Instance Attribute Details

#fragmentsArray<String> (readonly)

Returns the string fragments, i.e. the individual "words" for wrapping.

Returns:

  • (Array<String>)


22
23
24
# File 'core-docs/toys/wrappable_string.rb', line 22

def fragments
  @fragments
end

Class Method Details

.make(obj) ⇒ Toys::WrappableString

Make the given object a WrappableString. If the object is already a WrappableString, return it. Otherwise, treat it as a string or an array of strings and wrap it in a WrappableString.

Parameters:

Returns:



106
107
108
# File 'core-docs/toys/wrappable_string.rb', line 106

def self.make(obj)
  # Source available in the toys-core gem
end

.make_array(objs) ⇒ Array<Toys::WrappableString>

Make the given object an array of WrappableString.

Parameters:

Returns:



116
117
118
# File 'core-docs/toys/wrappable_string.rb', line 116

def self.make_array(objs)
  # Source available in the toys-core gem
end

.wrap_lines(strs, width, width2 = nil) ⇒ Array<String>

Wraps an array of lines to the given width.

Parameters:

  • strs (Array<WrappableString>)

    Array of strings to wrap.

  • width (Integer, nil)

    Width in characters, or nil for infinite.

  • width2 (Integer, nil) (defaults to: nil)

    Width in characters for the second and subsequent lines, or nil to use the same as width.

Returns:

  • (Array<String>)

    Wrapped lines



93
94
95
# File 'core-docs/toys/wrappable_string.rb', line 93

def self.wrap_lines(strs, width, width2 = nil)
  # Source available in the toys-core gem
end

Instance Method Details

#+(other) ⇒ WrappableString

Returns a new WrappaableString whose content is the concatenation of this WrappableString with another WrappableString.

Parameters:

Returns:



31
32
33
# File 'core-docs/toys/wrappable_string.rb', line 31

def +(other)
  # Source available in the toys-core gem
end

#==(other) ⇒ Boolean Also known as: eql?

Tests two wrappable strings for equality

Parameters:

  • other (Object)

Returns:

  • (Boolean)


57
58
59
# File 'core-docs/toys/wrappable_string.rb', line 57

def ==(other)
  # Source available in the toys-core gem
end

#empty?Boolean

Returns true if the string is empty (i.e. has no fragments)

Returns:

  • (Boolean)


39
40
41
# File 'core-docs/toys/wrappable_string.rb', line 39

def empty?
  # Source available in the toys-core gem
end

#hashInteger

Returns a hash code for this object

Returns:

  • (Integer)


66
67
68
# File 'core-docs/toys/wrappable_string.rb', line 66

def hash
  # Source available in the toys-core gem
end

#stringString Also known as: to_s

Returns the string without any wrapping

Returns:

  • (String)


47
48
49
# File 'core-docs/toys/wrappable_string.rb', line 47

def string
  # Source available in the toys-core gem
end

#wrap(width, width2 = nil) ⇒ Array<String>

Wraps the string to the given width.

Parameters:

  • width (Integer, nil)

    Width in characters, or nil for infinite.

  • width2 (Integer, nil) (defaults to: nil)

    Width in characters for the second and subsequent lines, or nil to use the same as width.

Returns:

  • (Array<String>)

    Wrapped lines



79
80
81
# File 'core-docs/toys/wrappable_string.rb', line 79

def wrap(width, width2 = nil)
  # Source available in the toys-core gem
end