module RSS::Utils

Public Instance Methods

element_initialize_arguments?(args) click to toggle source
# File lib/rss/utils.rb, line 35
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) click to toggle source
# File lib/rss/utils.rb, line 12
def get_file_and_line_from_caller(i=0)
  file, line, = caller[i].split(':')
  line = line.to_i
  line += 1 if i.zero?
  [file, line]
end
h(s)
Alias for: html_escape
html_escape(s) click to toggle source

escape '&', '“', '<' and '>' for use in HTML.

# File lib/rss/utils.rb, line 20
def html_escape(s)
  s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end
Also aliased as: h
new_with_value_if_need(klass, value) click to toggle source

If value is an instance of class klass, return it, else create a new instance of klass with value value.

# File lib/rss/utils.rb, line 27
def new_with_value_if_need(klass, value)
  if value.is_a?(klass)
    value
  else
    klass.new(value)
  end
end
to_class_name(name) click to toggle source

Convert a name_with_underscores to CamelCase.

# 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