lib/hirb/helpers/table.rb in hirb-0.4.5 vs lib/hirb/helpers/table.rb in hirb-0.5.0
- old
+ new
@@ -86,10 +86,11 @@
# [*:resize*] Resizes table to display all columns in allowed :max_width. Default is true. Setting this false will display the full
# length of each field.
# [*:number*] When set to true, numbers rows by adding a :hirb_number column as the first column. Default is false.
# [*:change_fields*] A hash to change old field names to new field names. This can also be an array of new names but only for array rows.
# This is useful when wanting to change auto-generated keys to more user-friendly names i.e. for array rows.
+ # [*:grep_fields*] A regexp that selects which fields to display. By default this is not set and applied.
# [*:filters*] A hash of fields and their filters, applied to every row in a field. A filter can be a proc, an instance method
# applied to the field value or a Filters method. Also see the filter_classes attribute below.
# [*:header_filter*] A filter, like one in :filters, that is applied to all headers after the :headers option.
# [*:filter_any*] When set to true, any cell defaults to being filtered by its class in :filter_classes.
# Default Hirb::Helpers::Table.filter_any().
@@ -138,9 +139,10 @@
raise ArgumentError, "Table must be an array of hashes or array of arrays" unless rows.is_a?(Array) &&
(rows[0].is_a?(Hash) or rows[0].is_a?(Array) or rows.empty?)
@options = {:description=>true, :filters=>{}, :change_fields=>{}, :escape_special_chars=>true,
:filter_any=>Helpers::Table.filter_any, :resize=>true}.merge(options)
@fields = set_fields(rows)
+ @fields = @fields.select {|e| e.to_s[@options[:grep_fields]] } if @options[:grep_fields]
@rows = set_rows(rows)
@headers = set_headers
if @options[:number]
@headers[:hirb_number] ||= "number"
@fields.unshift :hirb_number