]> git.r.bdr.sh - rbdr/lyricli.rb/blame - lib/lyricli/util.rb
Adds skeletons for Exceptions
[rbdr/lyricli.rb] / lib / lyricli / util.rb
CommitLineData
b8498f5c 1module Lyricli
34d0bf15 2 # This module contains several utility functions.
b8498f5c 3 module Util
34d0bf15
BB
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.
b8498f5c
BB
9 def camelize(str)
10 str.split('_').map {|w| w.capitalize}.join
11 end
12
34d0bf15
BB
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
b8498f5c 18 def parse_class(class_name)
d3e32008
BB
19 begin
20 path = "Sources::#{class_name}"
21 return eval(path)
b8498f5c 22 rescue NameError
d3e32008
BB
23 return nil
24 end
25 end
26
34d0bf15
BB
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
d3e32008
BB
32 def sanitize_param(p)
33 URI.encode_www_form_component(p.gsub(/ /, "+")).gsub("%2B", "+")
b8498f5c
BB
34 end
35 end
36end