class PulseAnalysis::Console::Table
Attributes
content[R]
Public Class Methods
build(report)
click to toggle source
@param [PulseAnalysis::Report] report @return [PulseAnalysis::Console::Table]
# File lib/pulse-analysis/console/table.rb, line 13 def self.build(report) table = new(report) table.build table end
new(report)
click to toggle source
@param [PulseAnalysis::Report] report
# File lib/pulse-analysis/console/table.rb, line 20 def initialize(report) @report = report end
Public Instance Methods
build()
click to toggle source
Populate the table content @return [Terminal::Table]
# File lib/pulse-analysis/console/table.rb, line 26 def build @content = Terminal::Table.new(title: "Pulse Analysis", headings: header) do |table| @report.items.each { |item| table << build_row(item) } end end
Private Instance Methods
build_row(item)
click to toggle source
Build a single table row with the given report item @param [Hash] item @return [Array<String>]
# File lib/pulse-analysis/console/table.rb, line 55 def build_row(item) row = [item[:description]] if item[:value].kind_of?(Array) # item has multiple units of measure item[:value].each_with_index do |value, i| cell = { value: "#{value[:value]} (#{value[:unit]})", } # make up remaining colspan if item[:value].last == value cell[:colspan] = value_colspan - i end row << cell end else # item has single unit of measure value = item[:value] row << { value: "#{value[:value]} (#{value[:unit]})", colspan: value_colspan # full width } end row end
header()
click to toggle source
Table
header @return [Array<Hash, String>]
# File lib/pulse-analysis/console/table.rb, line 36 def header [ "Item", { value: "Value", colspan: value_colspan } ] end
value_colspan()
click to toggle source
How many columns should the 'value' row be? @return [Integer]
# File lib/pulse-analysis/console/table.rb, line 48 def value_colspan @value_colspan ||= @report.items.map { |item| item[:value] }.map(&:count).max end