class Array
Public Instance Methods
to_table()
click to toggle source
# File lib/mergetrain_check/formatter.rb, line 67 def to_table output = '' column_sizes = self.reduce([]) do |lengths, row| if row.nil? lengths else row.each_with_index.map{|iterand, index| [lengths[index] || 0, iterand.to_s.length + count_emojis(iterand.to_s)].max} end end output += head = '-' * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1) + "\n" self.each_with_index do |row, idx| if row.nil? row = column_sizes.map { |l| '-' * l } output += '| ' + row.join(' | ') + ' |' + "\n" else row = row.fill(nil, row.size..(column_sizes.size - 1)) row = row.each_with_index.map{|v, i| v = v.to_s + ' ' * (column_sizes[i] - v.to_s.length - count_emojis(v.to_s))} output += '| ' + row.join(' | ') + ' |' + "\n" end end output += head end
Private Instance Methods
count_emojis(string)
click to toggle source
# File lib/mergetrain_check/formatter.rb, line 92 def count_emojis(string) string.scan(/[\u{1F300}-\u{1F5FF}|\u{1F1E6}-\u{1F1FF}|\u{2700}-\u{27BF}|\u{1F900}-\u{1F9FF}|\u{1F600}-\u{1F64F}|\u{1F680}-\u{1F6FF}|\u{2600}-\u{26FF}]/).length end