module Lyricli::Util

This module contains several utility functions.

Public Instance Methods

camelize(str) click to toggle source

Transforms a string from snake_case to UpperCamelCase

@param [String] str the string that will be Camelized @return [String] the Camelized string.

# File lib/lyricli/util.rb, line 9
def camelize(str)
  str.split('_').map {|w| w.capitalize}.join
end
parse_class(class_name) click to toggle source

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

@param [String] class_name the snake_case name of the class to search for. @return [Class,nil] the found class or nil

# 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
sanitize_param(p) click to toggle source

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

@param [String] p the parameter to be sanitized @return [String] the sanitized parameter

# File lib/lyricli/util.rb, line 32
def sanitize_param(p)
  CGI.escape(p.gsub(/ /, "+")).gsub("%2B", "+")
end