Line | |
---|
1 | module RSS
|
---|
2 | module Utils
|
---|
3 | module_function
|
---|
4 |
|
---|
5 | # Convert a name_with_underscores to CamelCase.
|
---|
6 | def to_class_name(name)
|
---|
7 | name.split(/_/).collect do |part|
|
---|
8 | "#{part[0, 1].upcase}#{part[1..-1]}"
|
---|
9 | end.join("")
|
---|
10 | end
|
---|
11 |
|
---|
12 | def get_file_and_line_from_caller(i=0)
|
---|
13 | file, line, = caller[i].split(':')
|
---|
14 | [file, line.to_i]
|
---|
15 | end
|
---|
16 |
|
---|
17 | # escape '&', '"', '<' and '>' for use in HTML.
|
---|
18 | def html_escape(s)
|
---|
19 | s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
---|
20 | end
|
---|
21 | alias h html_escape
|
---|
22 |
|
---|
23 | # If +value+ is an instance of class +klass+, return it, else
|
---|
24 | # create a new instance of +klass+ with value +value+.
|
---|
25 | def new_with_value_if_need(klass, value)
|
---|
26 | if value.is_a?(klass)
|
---|
27 | value
|
---|
28 | else
|
---|
29 | klass.new(value)
|
---|
30 | end
|
---|
31 | end
|
---|
32 |
|
---|
33 | def element_initialize_arguments?(args)
|
---|
34 | [true, false].include?(args[0]) and args[1].is_a?(Hash)
|
---|
35 | end
|
---|
36 | end
|
---|
37 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.