Module: Kutils::FormatUtils

Defined in:
lib/utils/format_utils.rb

Overview

FormatUtils provides formatting helpers for markdown and colored text.

Class Method Summary collapse

Class Method Details

.color_code(color) ⇒ Integer

Get ANSI color code

Parameters:

  • color (Symbol)

Returns:

  • (Integer)


28
29
30
# File 'lib/utils/format_utils.rb', line 28

def self.color_code(color)
  { red: 31, green: 32, yellow: 33, blue: 34 }[color] || 0
end

.color_text(text, color) ⇒ String

Colorize text in terminal

Parameters:

  • text (String)
  • color (Symbol)

Returns:

  • (String)


21
22
23
# File 'lib/utils/format_utils.rb', line 21

def self.color_text(text, color)
  "\e[#{color_code(color)}m#{text}\e[0m"
end

.markdown_title(title) ⇒ String

Format a markdown title

Parameters:

  • title (String)

Returns:

  • (String)


13
14
15
# File 'lib/utils/format_utils.rb', line 13

def self.markdown_title(title)
  "# #{title}\n\n"
end