Class: Wrapomatic::Wrapper
- Inherits:
-
Object
- Object
- Wrapomatic::Wrapper
- Defined in:
- lib/wrapomatic/wrapper.rb
Overview
Wrap several lines
Instance Attribute Summary collapse
-
#columns ⇒ Integer
readonly
The column cutoff.
-
#indents ⇒ Integer
readonly
The indentation level.
-
#lines ⇒ Array<String>
readonly
The text after wrapping as individual lines.
-
#text ⇒ String
readonly
The text to wrap.
Instance Method Summary collapse
-
#initialize(text, indents = 0, columns = 80) ⇒ Wrapper
constructor
A new instance of Wrapper.
-
#wrapped ⇒ String
The text wrapped to the desired indentation level and column cutoff.
Constructor Details
#initialize(text, indents = 0, columns = 80) ⇒ Wrapper
Returns a new instance of Wrapper.
28 29 30 31 32 |
# File 'lib/wrapomatic/wrapper.rb', line 28 def initialize(text, indents = 0, columns = 80) @text, @indents, @columns = text, indents, columns @lines = [] spit_some_mad_fire end |
Instance Attribute Details
#columns ⇒ Integer (readonly)
Returns the column cutoff.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wrapomatic/wrapper.rb', line 18 class Wrapper attr_reader :text, :lines, :indents, :columns # @param text [String] the text to wrap # # @param indents [Integer] the level to which each line should be # indented # # @param columns [Integer] the column to which each line should be # wrapped def initialize(text, indents = 0, columns = 80) @text, @indents, @columns = text, indents, columns @lines = [] spit_some_mad_fire end # The text wrapped to the desired indentation level and column cutoff # # @return [String] the wrapped text, joined by newlines def wrapped @lines.join("\n") end private def spit_some_mad_fire @lines = unwrapped_lines.map {|line| Line.new(line, indents, columns).wrapped }.flatten end def unwrapped_lines text.split("\n") end end |
#indents ⇒ Integer (readonly)
Returns the indentation level.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wrapomatic/wrapper.rb', line 18 class Wrapper attr_reader :text, :lines, :indents, :columns # @param text [String] the text to wrap # # @param indents [Integer] the level to which each line should be # indented # # @param columns [Integer] the column to which each line should be # wrapped def initialize(text, indents = 0, columns = 80) @text, @indents, @columns = text, indents, columns @lines = [] spit_some_mad_fire end # The text wrapped to the desired indentation level and column cutoff # # @return [String] the wrapped text, joined by newlines def wrapped @lines.join("\n") end private def spit_some_mad_fire @lines = unwrapped_lines.map {|line| Line.new(line, indents, columns).wrapped }.flatten end def unwrapped_lines text.split("\n") end end |
#lines ⇒ Array<String> (readonly)
Returns the text after wrapping as individual lines.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wrapomatic/wrapper.rb', line 18 class Wrapper attr_reader :text, :lines, :indents, :columns # @param text [String] the text to wrap # # @param indents [Integer] the level to which each line should be # indented # # @param columns [Integer] the column to which each line should be # wrapped def initialize(text, indents = 0, columns = 80) @text, @indents, @columns = text, indents, columns @lines = [] spit_some_mad_fire end # The text wrapped to the desired indentation level and column cutoff # # @return [String] the wrapped text, joined by newlines def wrapped @lines.join("\n") end private def spit_some_mad_fire @lines = unwrapped_lines.map {|line| Line.new(line, indents, columns).wrapped }.flatten end def unwrapped_lines text.split("\n") end end |
#text ⇒ String (readonly)
Returns the text to wrap.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wrapomatic/wrapper.rb', line 18 class Wrapper attr_reader :text, :lines, :indents, :columns # @param text [String] the text to wrap # # @param indents [Integer] the level to which each line should be # indented # # @param columns [Integer] the column to which each line should be # wrapped def initialize(text, indents = 0, columns = 80) @text, @indents, @columns = text, indents, columns @lines = [] spit_some_mad_fire end # The text wrapped to the desired indentation level and column cutoff # # @return [String] the wrapped text, joined by newlines def wrapped @lines.join("\n") end private def spit_some_mad_fire @lines = unwrapped_lines.map {|line| Line.new(line, indents, columns).wrapped }.flatten end def unwrapped_lines text.split("\n") end end |
Instance Method Details
#wrapped ⇒ String
The text wrapped to the desired indentation level and column cutoff
37 38 39 |
# File 'lib/wrapomatic/wrapper.rb', line 37 def wrapped @lines.join("\n") end |