]> git.r.bdr.sh - rbdr/lyricli.rb/blame_incremental - lib/lyricli/util.rb
Merge pull request #2 from orlando/master
[rbdr/lyricli.rb] / lib / lyricli / util.rb
... / ...
CommitLineData
1module Lyricli
2 # This module contains several utility functions.
3 module Util
4
5 # Transforms a string from snake_case to UpperCamelCase
6 #
7 # @param [String] str the string that will be Camelized
8 # @return [String] the Camelized string.
9 def camelize(str)
10 str.split('_').map {|w| w.capitalize}.join
11 end
12
13 # Takes a class name in snake_case and attempts to find the corresponding
14 # class from the sources.
15 #
16 # @param [String] class_name the snake_case name of the class to search for.
17 # @return [Class,nil] the found class or nil
18 def parse_class(class_name)
19 begin
20 path = "Sources::#{class_name}"
21 return eval(path)
22 rescue NameError
23 return nil
24 end
25 end
26
27 # Simply escapes a param and substitutes spaces and escaped plus signs for
28 # plus signs.
29 #
30 # @param [String] p the parameter to be sanitized
31 # @return [String] the sanitized parameter
32 def sanitize_param(p)
33 CGI.escape(p.gsub(/ /, "+")).gsub("%2B", "+")
34 end
35 end
36end