Class: Shoulda::Matchers::Line
- Inherits:
-
Object
- Object
- Shoulda::Matchers::Line
- Defined in:
- lib/shoulda/matchers/util/word_wrap.rb
Constant Summary collapse
- OFFSETS =
{ left: -1, right: +1 }.freeze
Instance Method Summary collapse
-
#initialize(line, indent: 0) ⇒ Line
constructor
A new instance of Line.
- #wrap ⇒ Object
Constructor Details
#initialize(line, indent: 0) ⇒ Line
Returns a new instance of Line.
119 120 121 122 123 124 |
# File 'lib/shoulda/matchers/util/word_wrap.rb', line 119 def initialize(line, indent: 0) @indent = indent @original_line = @line_to_wrap = Text.new(line) @indentation = ' ' * indent @indentation_read = false end |
Instance Method Details
#wrap ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/shoulda/matchers/util/word_wrap.rb', line 126 def wrap if line_to_wrap.indented? [line_to_wrap] else lines = [] loop do @previous_line_to_wrap = line_to_wrap new_line = (indentation || '') + line_to_wrap result = wrap_line(new_line) lines << normalize_whitespace(result[:fitted_line]) unless @indentation_read @indentation = read_indentation @indentation_read = true end @line_to_wrap = result[:leftover] if line_to_wrap.to_s.empty? || previous_line_to_wrap == line_to_wrap break end end lines end end |