Module: Lumos::Formatters::BaseChopper

Included in:
Base
Defined in:
lib/lumos/formatters/base_chopper.rb

Instance Method Summary collapse

Instance Method Details

#chopped_messageObject



4
5
6
# File 'lib/lumos/formatters/base_chopper.rb', line 4

def chopped_message
  message.scan(/.{1,#{( length > message_length ? message_length : length )}}/)
end

#chopped_message_lengthObject



8
9
10
# File 'lib/lumos/formatters/base_chopper.rb', line 8

def chopped_message_length
  chopped_message[0].size
end

#chopping_last_line?(line) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/lumos/formatters/base_chopper.rb', line 21

def chopping_last_line?(line)
  chopped_message.index(line) == chopped_message.size - 1
end

#chopping_line(line) ⇒ Object



17
18
19
# File 'lib/lumos/formatters/base_chopper.rb', line 17

def chopping_line(line)
  "\n" if chopped_message.size > 1 && !chopping_last_line?(line)
end

#chopping_padding(line) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/lumos/formatters/base_chopper.rb', line 25

def chopping_padding(line)
  if chopping_last_line?(line)
    first_line = chopped_message.first.size
    last_line  = chopped_message.last.size
    " " * (first_line - last_line) if first_line > last_line
  end
end

#iterate_chopped_lines(string = "") ⇒ Object



12
13
14
15
# File 'lib/lumos/formatters/base_chopper.rb', line 12

def iterate_chopped_lines(string = "")
  chopped_message.each{ |line| string += yield line }
  string
end