Rex::Text::Ui::Table.new[find_by_colnames]
Add :[] to ...Ui::Table allowing user to pass multiple colnames. Returns a new table with only those columns and their rows. Useful when using Rex to filter output, prep CSV, etc. Testing: ``` t = Rex::Ui::Text::Table.new('Columns' => ['a','b','c']) t << ['x','y','z'] t << ['p','q','r'] t['a','c'] => a c - - p r x z ```bug/bundler_fix
parent
79a72a18a9
commit
ed3b1cecd4
|
@ -212,6 +212,24 @@ class Table
|
||||||
rows << '__hr__'
|
rows << '__hr__'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns new sub-table with headers and rows maching column names submitted
|
||||||
|
#
|
||||||
|
def [](*colnames)
|
||||||
|
tbl = self.class.new('Indent' => self.indent,'Header' => self.header,'Columns' => colnames)
|
||||||
|
idx = []
|
||||||
|
colnames.each do |colname|
|
||||||
|
idx << self.columns.index(colname)
|
||||||
|
end
|
||||||
|
self.rows.each do |oldrow|
|
||||||
|
newrow = []
|
||||||
|
idx.map {|i| newrow << oldrow[i]}
|
||||||
|
tbl << newrow
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
alias p print
|
alias p print
|
||||||
|
|
||||||
attr_accessor :header, :headeri # :nodoc:
|
attr_accessor :header, :headeri # :nodoc:
|
||||||
|
|
Loading…
Reference in New Issue