Method: CommentBox#to_s
- Defined in:
- lib/commentbox.rb
#to_s ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/commentbox.rb', line 144 def to_s # exact value of spaceLine is calculated if @spacelines is true, otherwise it's just an empty string spaceLine = @spacelines ? [@style[:oddlines][0], ' ' * (@max_line_length + @padding * 2), @style[:oddlines][1], "\n"].join : '' # construct an array of lines, join them together and return return [ t_line(:begin), spaceLine, (0..@text.size - 1).map { |line| fmt_text_line line }, # this is a nested array and must be flattened spaceLine, t_line(:end) # flatten, map offset in front of each line if it's not empty, join them together, and remove trailing newline ].flatten.map { |line| line == '' ? '' : (' ' * @offset) << line }.join.chomp end |