Module: RSS::Utils
- Included in:
- BaseListener, BaseModel, Converter, Element, XMLStyleSheet
- Defined in:
- lib/rss/utils.rb
Class Method Summary collapse
- .element_initialize_arguments?(args) ⇒ Boolean
- .get_file_and_line_from_caller(i = 0) ⇒ Object
-
.html_escape(s) ⇒ Object
(also: h)
escape '&', '"', '<' and '>' for use in HTML.
-
.new_with_value_if_need(klass, value) ⇒ Object
If
valueis an instance of classklass, return it, else create a new instance ofklasswith valuevalue. -
.to_class_name(name) ⇒ Object
Convert a name_with_underscores to CamelCase.
Class Method Details
.element_initialize_arguments?(args) ⇒ Boolean
33 34 35 |
# File 'lib/rss/utils.rb', line 33 def element_initialize_arguments?(args) [true, false].include?(args[0]) and args[1].is_a?(Hash) end |
.get_file_and_line_from_caller(i = 0) ⇒ Object
12 13 14 15 |
# File 'lib/rss/utils.rb', line 12 def get_file_and_line_from_caller(i=0) file, line, = caller[i].split(':') [file, line.to_i] end |
.html_escape(s) ⇒ Object Also known as: h
escape '&', '"', '<' and '>' for use in HTML.
18 19 20 |
# File 'lib/rss/utils.rb', line 18 def html_escape(s) s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<") end |
.new_with_value_if_need(klass, value) ⇒ Object
If value is an instance of class klass, return it, else
create a new instance of klass with value value.
25 26 27 28 29 30 31 |
# File 'lib/rss/utils.rb', line 25 def new_with_value_if_need(klass, value) if value.is_a?(klass) value else klass.new(value) end end |
.to_class_name(name) ⇒ Object
Convert a name_with_underscores to CamelCase.
6 7 8 9 10 |
# File 'lib/rss/utils.rb', line 6 def to_class_name(name) name.split(/_/).collect do |part| "#{part[0, 1].upcase}#{part[1..-1]}" end.join("") end |