Class: Verse::Padding
- Inherits:
-
Object
- Object
- Verse::Padding
- Defined in:
- lib/verse/padding.rb
Overview
A class responsible for text indentation
Class Method Summary collapse
-
.pad(text, padding, options) ⇒ Object
Pad content out.
Instance Method Summary collapse
-
#initialize(text, options = {}) ⇒ Padding
constructor
Initialize a Padding.
-
#pad(padding = (not_set = true), options = {}) ⇒ String
private
Apply padding to text.
Constructor Details
Class Method Details
.pad(text, padding, options) ⇒ Object
Pad content out
19 20 21 |
# File 'lib/verse/padding.rb', line 19 def self.pad(text, padding, ) new(text, ).pad(padding, ) end |
Instance Method Details
#pad(padding = (not_set = true), options = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply padding to text
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/verse/padding.rb', line 30 def pad(padding = (not_set = true), = {}) return text if @padding.empty? && not_set if !not_set @padding = Padder.parse(padding) end text_copy = text.dup column_width = maximum_length(text) elements = [] if @padding.top > 0 elements << (SPACE * column_width + NEWLINE) * @padding.top end elements << text_copy if @padding.bottom > 0 elements << (SPACE * column_width + NEWLINE) * @padding.bottom end elements.map { |el| pad_multi_line(el) }.join(NEWLINE) end |