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.

A WrappableString is an array of string "fragments" representing the atomic units that should not be split when word-wrapping. It should be possible to reconstruct the original string by joining these fragments with whitespace.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string = "") ⇒ WrappableString

Create a wrapped string.

You can pass either:

  • A single String, which will be split into fragments by whitespace.
  • An array of Strings representing the fragments explicitly.

Parameters:

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

    The string or array of string fragments



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

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>)


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

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:



118
119
120
# File 'core-docs/toys/wrappable_string.rb', line 118

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:



128
129
130
# File 'core-docs/toys/wrappable_string.rb', line 128

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



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

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:



41
42
43
# File 'core-docs/toys/wrappable_string.rb', line 41

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)


69
70
71
# File 'core-docs/toys/wrappable_string.rb', line 69

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)


50
51
52
# File 'core-docs/toys/wrappable_string.rb', line 50

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

#hashInteger

Returns a hash code for this object

Returns:

  • (Integer)


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

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

#stringString Also known as: to_s

Returns the string without any wrapping

Returns:

  • (String)


59
60
61
# File 'core-docs/toys/wrappable_string.rb', line 59

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



91
92
93
# File 'core-docs/toys/wrappable_string.rb', line 91

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