Module: SkillBench::Services::FormattingHelpers

Included in:
DeltaTableFormatter, FeedbackGenerator, IterationFormatter
Defined in:
lib/skill_bench/services/formatting_helpers.rb

Overview

Shared string-formatting utilities used across output formatters.

Class Method Summary collapse

Class Method Details

.delta_str(delta) ⇒ String

Formats a numeric delta with a +/- sign.

Parameters:

  • delta (Numeric)

    The delta value.

Returns:

  • (String)

    Formatted delta string.



21
22
23
# File 'lib/skill_bench/services/formatting_helpers.rb', line 21

def delta_str(delta)
  delta >= 0 ? "+#{delta}" : delta.to_s
end

.humanize(name) ⇒ String

Converts a snake_case name to Title Case.

Parameters:

  • name (String, Symbol)

    The dimension name.

Returns:

  • (String)

    Human-readable name.



13
14
15
# File 'lib/skill_bench/services/formatting_helpers.rb', line 13

def humanize(name)
  name.to_s.split('_').map(&:capitalize).join(' ')
end

.trend_icon(direction) ⇒ String

Returns the Unicode arrow icon for a trend direction.

Parameters:

  • direction (Symbol)

    :improved, :regressed, or :unchanged.

Returns:

  • (String)

    Arrow icon.



40
41
42
# File 'lib/skill_bench/services/formatting_helpers.rb', line 40

def trend_icon(direction)
  { improved: '', regressed: '', unchanged: '' }.fetch(direction, '?')
end

.truncate(text, max_length) ⇒ String

Truncates a string to a maximum length with ellipsis.

Parameters:

  • text (String)

    The text to truncate.

  • max_length (Integer)

    Maximum length.

Returns:

  • (String)

    Truncated text.



30
31
32
33
34
# File 'lib/skill_bench/services/formatting_helpers.rb', line 30

def truncate(text, max_length)
  return text if text.length <= max_length

  "#{text[0...max_length]}..."
end