|
Methods
Public Instance methods
[ show source ]
# File lib/unroller.rb, line 926
926: def make_it_fit(max_width, overflow = :chop_right)
927: returning(string = self) do
928: if string.length_without_color > max_width # Wider than desired column width; Needs to be chopped.
929: unless max_width < 4 # Is there even enough room for it if it *is* chopped? If not, then don't even bother.
930: #Kernel.p overflow
931: if overflow == :chop_left
932: #puts "making string (#{string.length_without_color}) fit within #{max_width} by doing a :chop_left"
933: #puts "chopping '#{string}' at -(#{max_width} - 3) .. -1!"
934: chopped_part = string[-(max_width - 3) .. -1]
935: string.replace '...' + chopped_part
936: elsif overflow == :chop_right
937: #puts "making string (#{string.length_without_color}) fit within #{max_width} by doing a :chop_right"
938: chopped_part = string[0 .. (max_width - 3)]
939: string.replace chopped_part + '...'
940: end
941: else
942: string = ''
943: end
944: end
945: end
946: end
Makes the first character bold and underlined. Makes the whole string of the given color. :todo: Move out to extensions/console/menu_item
[ show source ]
# File lib/unroller.rb, line 56
56: def menu_item(color = :white, letter = self[0..0], which_occurence = 0)
57: index = index_all(/#{letter}/)[which_occurence]
58: raise "Could not find a #{which_occurence}th occurence of '#{letter}' in string '#{self}'" if index.nil?
59: before = self[0..index-1].send(color) unless index == 0
60: middle = self[index..index].send(color).bold.underline
61: after = self[index+1..-1].send(color)
62: before.to_s + middle + after
63: end