class Convoy::Formatter::StringSplitter
Attributes
max_segment_width[R]
Public Class Methods
new(max_segment_width, options = {})
click to toggle source
# File lib/convoy/formatter/string_splitter.rb, line 6 def initialize(max_segment_width, options = {}) @max_segment_width = max_segment_width #@first_segment_max_length = options[:first_segment_max_length] || max_segment_width end
Public Instance Methods
split(input_string)
click to toggle source
# File lib/convoy/formatter/string_splitter.rb, line 11 def split(input_string) input_strings = input_string.split("\n") [split_strings(input_strings)].flatten #first_string = strings.shift #other_strings = strings #result = [split_first_string(first_string) + split_strings(other_strings)].flatten #result end
Private Instance Methods
split_string(string)
click to toggle source
# File lib/convoy/formatter/string_splitter.rb, line 36 def split_string(string) result = [] if string.length > max_segment_width first_part = string.slice(0, max_segment_width) second_part = string.slice(max_segment_width..-1) result << first_part result << split_string(second_part) else result << string end result end
split_strings(strings)
click to toggle source
def split_first_string(string) if first_segment_max_length >= string.length split_string
(string) else first = string.slice(0, first_segment_max_length) last = string.slice(first_segment_max_length..-1) split_strings
([first, last]) end end
# File lib/convoy/formatter/string_splitter.rb, line 32 def split_strings(strings) strings.map { |s| split_string(s) } end