Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/colors.rb

Overview

simple vt100 colors

Instance Method Summary collapse

Instance Method Details

#apply(*colors) ⇒ String

Applies the provided list of string decoration (colors).

Parameters:

  • colors (Array<Symbol>)

    List of decorations.

Returns:

  • (String)

    Enhanced String.



64
65
66
# File 'lib/aspera/colors.rb', line 64

def apply(*colors)
  colors.reduce(self){ |s, c| s.public_send(c)}
end

#capital_to_snakeObject

Transform capitalized to snake case



69
70
71
72
73
# File 'lib/aspera/colors.rb', line 69

def capital_to_snake
  return gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .downcase
end

#snake_to_capitalObject

Transform snake case to capitalized



76
77
78
# File 'lib/aspera/colors.rb', line 76

def snake_to_capital
  split('_').map(&:capitalize).join
end