From 81f786098f10d77ca5d55cdfb1be18309d39b4cc Mon Sep 17 00:00:00 2001 From: Neil Matatall Date: Tue, 10 Apr 2012 18:25:49 -0700 Subject: [PATCH] Move to util class --- lib/brakeman/report.rb | 23 +---------------------- lib/brakeman/util.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/brakeman/report.rb b/lib/brakeman/report.rb index 71056c6e..2c23e007 100644 --- a/lib/brakeman/report.rb +++ b/lib/brakeman/report.rb @@ -4,6 +4,7 @@ require 'brakeman/processors/output_processor' require 'brakeman/util' require 'terminal-table' require 'highline/system_extensions' + require "csv" if CSV.const_defined? :Reader # Ruby 1.8 compatible @@ -617,26 +618,4 @@ class Brakeman::Report template = ERB.new(content) template.result(bind) end - - def truncate str - @terminal_width ||= ::HighLine::SystemExtensions::terminal_size[0] - lines = str.lines - - lines.map do |line| - if line.chomp.length > @terminal_width - line[0..(@terminal_width - 3)] + ">>" - else - line - end - end.join - end - - # rely on Terminal::Table to build the structure, extract the data out in CSV format - def table_to_csv table - output = CSV.generate_line(table.headings.cells.map{|cell| cell.to_s.strip}) - table.rows.each do |row| - output << CSV.generate_line(row.cells.map{|cell| cell.to_s.strip}) - end - output - end end diff --git a/lib/brakeman/util.rb b/lib/brakeman/util.rb index 5e9ff8ac..5a4c9810 100644 --- a/lib/brakeman/util.rb +++ b/lib/brakeman/util.rb @@ -324,4 +324,26 @@ module Brakeman::Util context end + + def truncate str + @terminal_width ||= ::HighLine::SystemExtensions::terminal_size[0] + lines = str.lines + + lines.map do |line| + if line.chomp.length > @terminal_width + line[0..(@terminal_width - 3)] + ">>" + else + line + end + end.join + end + + # rely on Terminal::Table to build the structure, extract the data out in CSV format + def table_to_csv table + output = CSV.generate_line(table.headings.cells.map{|cell| cell.to_s.strip}) + table.rows.each do |row| + output << CSV.generate_line(row.cells.map{|cell| cell.to_s.strip}) + end + output + end end -- GitLab