Module: Lyricli::Util
- Included in:
- LyricsEngine, SourceManager
- Defined in:
- lib/lyricli/util.rb
Overview
This module contains several utility functions.
Instance Method Summary (collapse)
-
- (String) camelize(str)
Transforms a string from snake_case to UpperCamelCase.
-
- (Class?) parse_class(class_name)
Takes a class name in snake_case and attempts to find the corresponding class from the sources.
-
- (String) sanitize_param(p)
Simply escapes a param and substitutes spaces and escaped plus signs for plus signs.
Instance Method Details
- (String) camelize(str)
Transforms a string from snake_case to UpperCamelCase
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.
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.
32 33 34 |
# File 'lib/lyricli/util.rb', line 32 def sanitize_param(p) URI.encode_www_form_component(p.gsub(/ /, "+")).gsub("%2B", "+") end |