commentbox 0.1.0 → 0.1.2
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 +20 -7
- 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: 922e9531c4f2d9e403c9343697e58086c40217a625de7b66b8b145c619b8eae9
|
4
|
+
data.tar.gz: 6d4ba601200f5fef70d43203dbc4e2ae4cd76d105c5e884cef96fccee26627ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f862760a55925ce00d08746251bc8512189e0acd301e6bb4c45d84cc42115da0fd97eb64eb508429ef959021c48e14361ddafe0e24e6ece5d9d9e09a776d4667
|
7
|
+
data.tar.gz: 9eed5ab62484e8acefad8dccc13ddd843555adcac89eb6cc37a23bbd4cf06f3ae760475e75f498ce3b678ea7291ea79e67ad46310d164824947b7d5857d10df9
|
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 : ''
|
@@ -139,16 +144,26 @@ private
|
|
139
144
|
@alignment = [ align ] * (@text.size)
|
140
145
|
# set @alignment directly if an array is given
|
141
146
|
elsif align.is_a? Array
|
147
|
+
align.map! { |a| a.to_sym }
|
142
148
|
# if the array is too short, fill it with the last element
|
143
149
|
if align.size < @text.size then (@text.size - align.size).times { align.push align.last } end
|
144
150
|
@alignment = align
|
151
|
+
elsif align.is_a? String
|
152
|
+
@alignment = [ align.to_sym ] * (@text.size)
|
145
153
|
else
|
146
|
-
raise 'CommentBox#alignment= : expected Symbol or
|
154
|
+
raise 'CommentBox#alignment= : expected Symbol, Array, or String here'
|
147
155
|
end
|
148
156
|
end
|
149
157
|
# if the number of lines is even, insert a blank line between the first and second lines
|
150
158
|
insert_line_if_even
|
151
159
|
end
|
160
|
+
def set_style (style)
|
161
|
+
if style == nil then @style = Styles[DefaultParams[:style]]
|
162
|
+
elsif style.is_a? Symbol then @style = Styles[style]
|
163
|
+
elsif style.is_a? Hash then @style = style
|
164
|
+
elsif style.is_a? String then @style = Styles[style.to_sym]
|
165
|
+
else raise 'CommentBox#style= : expected Symbol, Hash, or String here' end
|
166
|
+
end
|
152
167
|
def insert_line_if_even # also will delete a blank line if there is one
|
153
168
|
# stop this function from raising errors we don't really care about if the instance isn't fully constructed yet
|
154
169
|
if !(@text.is_a?(Array) && @alignment.is_a?(Array)) then return end
|
@@ -177,6 +192,4 @@ private
|
|
177
192
|
if line.is_even? then @style[:evenlines][0] + ret + @style[:evenlines][1] + "\n"
|
178
193
|
else @style[:oddlines][0] + ret + @style[:oddlines][1] + "\n" end
|
179
194
|
end
|
180
|
-
end
|
181
|
-
|
182
|
-
puts CommentBox.new "Lenny's box"
|
195
|
+
end
|