Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/core_ext/string/underline.rb,
lib/fedux_org_stdlib/core_ext/string.rb,
lib/fedux_org_stdlib/core_ext/string/characterize.rb,
lib/fedux_org_stdlib/core_ext/string/transliterate.rb

Overview

String

Instance Method Summary collapse

Instance Method Details

#characterizeObject

Convert string to characters only

This will remove accents and umlauts and other special characters

‘Donald E. Knütz’.characterize #=> ‘donald-e-knuth’

Examples:

Simple Example



14
15
16
# File 'lib/fedux_org_stdlib/core_ext/string/characterize.rb', line 14

def characterize
  transliterate.parameterize
end

#transliterateObject

Make umlauts less special

This will remove accents and umlauts and other specialities from characters.

ä => a á => a

‘Donald E. Knütz’.transliterate #=> ‘Donald E. Knutz’

Examples:

Simple Example



19
20
21
# File 'lib/fedux_org_stdlib/core_ext/string/transliterate.rb', line 19

def transliterate
  ActiveSupport::Inflector.transliterate(self)
end

#underline(character: '-') ⇒ String

Underline a string

Parameters:

  • character (String) (defaults to: '-')

    (‘-’) The character used to underline the string

Returns:

  • (String)

    The string + underline



11
12
13
14
15
16
17
# File 'lib/fedux_org_stdlib/core_ext/string/underline.rb', line 11

def underline(character: '-')
  result = []
  result << self
  result << gsub(/./, character)

  result.join("\n")
end