Module: Svelte::StringManipulator

Defined in:
lib/svelte/string_manipulator.rb

Overview

Provides helper methods to manipulate strings in order to generate valid constant and method names from them

Class Method Summary collapse

Class Method Details

.constant_name_for(string) ⇒ String

Generates a valid Ruby constant name as similar as possible to string

Parameters:

  • string (String)

    input string

Returns:

  • (String)

    a valid Ruby constant name based on string



11
12
13
14
15
# File 'lib/svelte/string_manipulator.rb', line 11

def constant_name_for(string)
  s = remove_invalid_characters(string)
  s = fixify(s)
  pascalize(s)
end

.method_name_for(string) ⇒ String

Generates a valid Ruby method name as similar as possible to string

Parameters:

  • string (String)

    input string

Returns:

  • (String)

    a valid Ruby method name based on string



20
21
22
23
24
# File 'lib/svelte/string_manipulator.rb', line 20

def method_name_for(string)
  s = remove_invalid_characters(string)
  s = fixify(s)
  snakify(s)
end