@@ -72,7 +72,7 @@ def initialize(opts = {})
72
72
self . prefix = opts [ 'Prefix' ] || ''
73
73
self . postfix = opts [ 'Postfix' ] || ''
74
74
self . colprops = [ ]
75
- self . scterm = opts [ 'SearchTerm' ] ? /#{ opts [ 'SearchTerm' ] } /mi : /./
75
+ self . scterm = /#{ opts [ 'SearchTerm' ] } /mi if opts [ 'SearchTerm' ]
76
76
77
77
self . sort_index = opts [ 'SortIndex' ] || 0
78
78
self . sort_order = opts [ 'SortOrder' ] || :forward
@@ -114,7 +114,7 @@ def to_s
114
114
if ( is_hr ( row ) )
115
115
str << hr_to_s
116
116
else
117
- str << row_to_s ( row ) if row_to_s ( row ) . match ( self . scterm )
117
+ str << row_to_s ( row ) if row_visible ( row )
118
118
end
119
119
}
120
120
@@ -130,10 +130,9 @@ def to_csv
130
130
str = ''
131
131
str << ( columns . join ( "," ) + "\n " )
132
132
rows . each { |row |
133
- next if is_hr ( row ) or ! ( row_to_s ( row ) . match ( self . scterm ) )
133
+ next if is_hr ( row ) || ! row_visible ( row )
134
134
str << ( row . map { |x |
135
135
x = x . to_s
136
-
137
136
x . gsub ( /[\r \n ]/ , ' ' ) . gsub ( /\s +/ , ' ' ) . gsub ( '"' , '""' )
138
137
} . map { |x | "\" #{ x } \" " } . join ( "," ) + "\n " )
139
138
}
@@ -298,6 +297,14 @@ def [](*col_names)
298
297
299
298
protected
300
299
300
+ #
301
+ # Returns if a row should be visible or not
302
+ #
303
+ def row_visible ( row )
304
+ return true if self . scterm . nil?
305
+ row_to_s ( row ) . match ( self . scterm )
306
+ end
307
+
301
308
#
302
309
# Defaults cell widths and alignments.
303
310
#
@@ -328,9 +335,7 @@ def columns_to_s # :nodoc:
328
335
padding = pad ( ' ' , last_col , last_idx )
329
336
nameline << padding
330
337
remainder = padding . length - cellpad
331
- if ( remainder < 0 )
332
- remainder = 0
333
- end
338
+ remainder = 0 if remainder < 0
334
339
barline << ( ' ' * ( cellpad + remainder ) )
335
340
end
336
341
@@ -391,7 +396,7 @@ def pad(chr, buf, colidx, use_cell_pad = true) # :nodoc:
391
396
if ( use_cell_pad )
392
397
val << ' ' * cellpad
393
398
end
394
-
399
+
395
400
return val
396
401
end
397
402
0 commit comments