yummi 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/yummi.rb +1 -1
- data/lib/yummi/text_box.rb +6 -6
- data/lib/yummi/version.rb +1 -1
- metadata +1 -1
data/lib/yummi.rb
CHANGED
@@ -187,7 +187,7 @@ module Yummi
|
|
187
187
|
# Aligns the text to both sides
|
188
188
|
def self.justify text, width
|
189
189
|
extra_spaces = width - text.size
|
190
|
-
return text if extra_spaces
|
190
|
+
return text if extra_spaces < 0
|
191
191
|
words = text.split ' '
|
192
192
|
return text if extra_spaces / (words.size - 1) > 2
|
193
193
|
until extra_spaces == 0
|
data/lib/yummi/text_box.rb
CHANGED
@@ -39,7 +39,7 @@ module Yummi
|
|
39
39
|
:content => ''
|
40
40
|
}.merge! params
|
41
41
|
@color = params[:color]
|
42
|
-
@content =
|
42
|
+
@content = []
|
43
43
|
end
|
44
44
|
|
45
45
|
#
|
@@ -56,7 +56,7 @@ module Yummi
|
|
56
56
|
#
|
57
57
|
def add text, params = {}
|
58
58
|
params = {
|
59
|
-
:width => @max_width
|
59
|
+
:width => @max_width,
|
60
60
|
:align => @default_align
|
61
61
|
}.merge! params
|
62
62
|
if params[:width]
|
@@ -64,7 +64,8 @@ module Yummi
|
|
64
64
|
words = text.gsub($/, ' ').split(' ')
|
65
65
|
buff = ''
|
66
66
|
words.each do |word|
|
67
|
-
if
|
67
|
+
# go to next line if the current word blows up the width limit
|
68
|
+
if buff.size + word.size >= width
|
68
69
|
_add_ buff, params
|
69
70
|
buff = ''
|
70
71
|
end
|
@@ -98,7 +99,7 @@ module Yummi
|
|
98
99
|
def to_s
|
99
100
|
width = 0
|
100
101
|
sizes = []
|
101
|
-
content.
|
102
|
+
content.each do |line|
|
102
103
|
size = (Yummi::Color::raw line.chomp).size
|
103
104
|
sizes << size
|
104
105
|
width = [width, size].max
|
@@ -108,7 +109,7 @@ module Yummi
|
|
108
109
|
buff = ''
|
109
110
|
buff << border
|
110
111
|
i = 0
|
111
|
-
content.
|
112
|
+
content.each do |line|
|
112
113
|
diff = width - sizes[i]
|
113
114
|
buff << pipe << line.chomp << (' ' * diff) << pipe << $/
|
114
115
|
i += 1
|
@@ -124,7 +125,6 @@ module Yummi
|
|
124
125
|
text = Yummi::Aligner.align params[:align], text, params[:width]
|
125
126
|
end
|
126
127
|
@content << Yummi.colorize(text, params[:color])
|
127
|
-
line_break
|
128
128
|
end
|
129
129
|
|
130
130
|
end
|
data/lib/yummi/version.rb
CHANGED