class Wrapomatic::Line

Wrap a single line

@!attribute [r] columns

@return [Integer] the columns cutoff

@!attribute [r] indents

@return [Integer] the indentation level

@!attribute [r] original

@return [String] the original text

Constants

INDENTATION

An indentation in Wrapomatic is two spaces

Attributes

columns[R]
indents[R]
original[R]

Public Class Methods

new(original, indents, columns) click to toggle source

@param original [String] a single line of text

@param indents [Integer] the number of indentation levels to which the

line should be wrapped

@param columns [Integer] the number of columns to which the line should be

wrapped

@raise [ArgumentError] if the provided text contains newline characters

# File lib/wrapomatic/line.rb, line 30
def initialize(original, indents, columns)
  @original, @indents, @columns = original, indents, columns
  raise ArgumentError.new('original may not contain newline') if contains_newline?
end

Public Instance Methods

indented() click to toggle source

The indented line before wrapping

@return [String] the line indented to the indentation level

# File lib/wrapomatic/line.rb, line 49
def indented
  "#{INDENTATION * indents}#{original}"
end
wrapped() click to toggle source

The result of wrapping the text to the provided indentation level and columns

@return [Array<String>] the original line broken into several lines that

adhere to the column cutoff and indentation level
# File lib/wrapomatic/line.rb, line 40
def wrapped
  @wrapped ||= indented.length <= columns ? 
    [indented] :
    Processor.process(self)
end

Private Instance Methods

contains_newline?() click to toggle source
# File lib/wrapomatic/line.rb, line 54
def contains_newline?
  original.chars.include?("\n")
end