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
-
.delta_str(delta) ⇒ String
Formats a numeric delta with a +/- sign.
-
.humanize(name) ⇒ String
Converts a snake_case name to Title Case.
-
.trend_icon(direction) ⇒ String
Returns the Unicode arrow icon for a trend direction.
-
.truncate(text, max_length) ⇒ String
Truncates a string to a maximum length with ellipsis.
Class Method Details
.delta_str(delta) ⇒ String
Formats a numeric delta with a +/- sign.
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.
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.
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.
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 |