commentbox 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/commentbox.rb +15 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c075de18d6c7e47412397f8429b95a4ccf4a510915c412912fecb899ea3c6e37
|
4
|
+
data.tar.gz: 293ef1564eed9d108736d08284df7cc9d7e8f04961e0918fc5be062071d0e7ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 544071b2459e49a38323151808d87d172d0e29785cddb4aa54ef708a74479c93bcfe0a61f13791d672d0c1d38308b59acc9f6e3943f9ed2f669f18c43c9fd8ba
|
7
|
+
data.tar.gz: a5ff842476987796f19f49b0523986e559b5868f3200b8fcf0b6b129407f4d43afeb87a87c43d5cede01ac66cfc842df1194e2502811a0d75fb173969584be6f
|
data/lib/commentbox.rb
CHANGED
@@ -78,10 +78,13 @@ class CommentBox
|
|
78
78
|
attr_writer :padding, :spacelines, :alignment, :offset
|
79
79
|
# I don't know how to call param= methods from the inside so I just use a set_param in private
|
80
80
|
def text= (value); set_text value; self end; def alignment= (value); set_alignment value; self end
|
81
|
-
def style= (value);
|
81
|
+
def style= (value); set_style value; self end
|
82
82
|
# there is no @stretch, stretch is just added to @max_line_length
|
83
83
|
# but, if stretch= is called, then @max_line_length must be recalculated
|
84
|
-
def stretch= (value)
|
84
|
+
def stretch= (value)
|
85
|
+
@max_line_length = @text.map(&:length).max + value
|
86
|
+
if !@max_line_length.is_even? then @max_line_length += 1 end
|
87
|
+
self end
|
85
88
|
|
86
89
|
def initialize (params) # params: {text: String or Array, style: Symbol, padding: Integer, spacelines: Boolean, alignment: Symbol or Array}
|
87
90
|
# for now require an argument of some sort
|
@@ -91,7 +94,7 @@ class CommentBox
|
|
91
94
|
if params.is_a? String then params = {text: params} end
|
92
95
|
|
93
96
|
# fill in a bunch of instance variables from params or default values
|
94
|
-
style_symbol = params[:style] || DefaultParams[:style]; @style = Styles[style_symbol]
|
97
|
+
# style_symbol = params[:style] || DefaultParams[:style]; @style = Styles[style_symbol]
|
95
98
|
@padding = params[:padding] || DefaultParams[:padding]
|
96
99
|
@offset = params[:offset] || DefaultParams[:offset]
|
97
100
|
# one of the options for this is false, so it's not gonna play nice with ||
|
@@ -100,7 +103,9 @@ class CommentBox
|
|
100
103
|
# call on some special methods to parse text and alignment
|
101
104
|
set_text params[:text]
|
102
105
|
set_alignment params[:alignment]
|
106
|
+
set_style params[:style]
|
103
107
|
@max_line_length += (params[:stretch] || DefaultParams[:stretch]).to_i
|
108
|
+
if !@max_line_length.is_even? then @max_line_length += 1 end
|
104
109
|
end
|
105
110
|
def to_s
|
106
111
|
spaceLine = @spacelines ? [@style[:oddlines][0], ' ' * (@max_line_length + @padding * 2), @style[:oddlines][1], "\n"].join : ''
|
@@ -149,6 +154,12 @@ private
|
|
149
154
|
# if the number of lines is even, insert a blank line between the first and second lines
|
150
155
|
insert_line_if_even
|
151
156
|
end
|
157
|
+
def set_style (style)
|
158
|
+
if style == nil then @style = Styles[DefaultParams[:style]]
|
159
|
+
elsif style.is_a? Symbol then @style = Styles[style]
|
160
|
+
elsif style.is_a? Hash then @style = style
|
161
|
+
else raise 'CommentBox#style= : expected Symbol or Hash here' end
|
162
|
+
end
|
152
163
|
def insert_line_if_even # also will delete a blank line if there is one
|
153
164
|
# stop this function from raising errors we don't really care about if the instance isn't fully constructed yet
|
154
165
|
if !(@text.is_a?(Array) && @alignment.is_a?(Array)) then return end
|
@@ -177,6 +188,4 @@ private
|
|
177
188
|
if line.is_even? then @style[:evenlines][0] + ret + @style[:evenlines][1] + "\n"
|
178
189
|
else @style[:oddlines][0] + ret + @style[:oddlines][1] + "\n" end
|
179
190
|
end
|
180
|
-
end
|
181
|
-
|
182
|
-
puts CommentBox.new "Lenny's box"
|
191
|
+
end
|