class Array
Public Instance Methods
obfuscate!(secure_keys = DEFAULT_SECURE_KEYS)
click to toggle source
# File lib/ectoplasm.rb, line 155 def obfuscate! secure_keys = DEFAULT_SECURE_KEYS self.map { |x| x.obfuscate!(secure_keys) } end
pretty(width: 25)
click to toggle source
# File lib/ectoplasm.rb, line 99 def pretty width: 25 return 'empty'.grey if self.length == 0 list_length = self.map { |x| x.to_s.length }.reduce(:+) return self.join ', ' if list_length && list_length < 30 self .select { |x| x != nil && x != '' } .map do |x| ' - ' + x.pretty(width: width-3).strip.gsub(/\n/, "\n ") end .join "\n" end
table(header: nil, mappings: {})
click to toggle source
# File lib/ectoplasm.rb, line 113 def table header: nil, mappings: {}, with_index: false, limit: 50 header = self[0].keys if header == nil heading = header.is_a?(Array) ? header : self[0].keys table_data = self.slice(0, limit).map do |row| heading.map do |key| mappings.has_key?(key) ? mappings[key][row, row[key]] : row[key] end end table_data.insert(0, heading) if header != false data_sizes = table_data.map do |row| row.map { |data| data.to_s.length } end column_sizes = data_sizes[0] .zip(*data_sizes[1..-1]) .map { |row| row.max } table = table_data.map { |row| column_sizes.zip row } table_str = '' table.each_with_index do |row, index| if with_index if index == 0 table_str += ' ' else table_str += "[#{index}] " end end row.each do |col_size, data| table_str += (data.to_s + ' ' * (col_size - data.to_s.length)) + ' ' end table_str += "\n" end table_str += '[...]' if self.count > limit print table_str end