Module: Lyricli::Util

Included in:
LyricsEngine, SourceManager
Defined in:
lib/lyricli/util.rb

Overview

This module contains several utility functions.

Instance Method Summary (collapse)

Instance Method Details

- (String) camelize(str)

Transforms a string from snake_case to UpperCamelCase

Parameters:

  • str (String)

    the string that will be Camelized

Returns:

  • (String)

    the Camelized string.



9
10
11
# File 'lib/lyricli/util.rb', line 9

def camelize(str)
  str.split('_').map {|w| w.capitalize}.join
end

- (Class?) parse_class(class_name)

Takes a class name in snake_case and attempts to find the corresponding class from the sources.

Parameters:

  • class_name (String)

    the snake_case name of the class to search for.

Returns:

  • (Class, nil)

    the found class or nil



18
19
20
21
22
23
24
25
# File 'lib/lyricli/util.rb', line 18

def parse_class(class_name)
  begin
    path = "Sources::#{class_name}"
    return eval(path)
  rescue NameError
    return nil
  end
end

- (String) sanitize_param(p)

Simply escapes a param and substitutes spaces and escaped plus signs for plus signs.

Parameters:

  • p (String)

    the parameter to be sanitized

Returns:

  • (String)

    the sanitized parameter



32
33
34
# File 'lib/lyricli/util.rb', line 32

def sanitize_param(p)
  URI.encode_www_form_component(p.gsub(/ /, "+")).gsub("%2B", "+")
end