Class: Rake::Funnel::Support::Timing::Report::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/funnel/support/timing/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stats: [], header: '', accessor: -> (_) { '' }) ⇒ Column

Returns a new instance of Column.



11
12
13
14
15
# File 'lib/rake/funnel/support/timing/report.rb', line 11

def initialize(stats: [], header: '', accessor: -> (_) { '' })
  @stats = stats
  @header = header
  @accessor = accessor
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



9
10
11
# File 'lib/rake/funnel/support/timing/report.rb', line 9

def header
  @header
end

Instance Method Details

#format_headerObject



24
25
26
# File 'lib/rake/funnel/support/timing/report.rb', line 24

def format_header
  @header.ljust(width)
end

#format_value(value) ⇒ Object



28
29
30
# File 'lib/rake/funnel/support/timing/report.rb', line 28

def format_value(value)
  @accessor.call(value).ljust(width)
end

#widthObject



17
18
19
20
21
22
# File 'lib/rake/funnel/support/timing/report.rb', line 17

def width
  longest_value = @stats.map { |s| @accessor.call(s) }.max_by { |m| m.length } || ''
  width = longest_value.length
  width = @header.length if width < @header.length
  width
end