Module: RSS::Utils

Defined in:
lib/rss/utils.rb

Defined Under Namespace

Modules: CSV, InheritedReader, YesCleanOther, YesOther

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) element_initialize_arguments?(args)

Returns:

  • (Boolean)


35
36
37
# File 'lib/rss/utils.rb', line 35

def element_initialize_arguments?(args)
  [true, false].include?(args[0]) and args[1].is_a?(Hash)
end

- (Object) get_file_and_line_from_caller(i = 0)



12
13
14
15
16
17
# 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

- (Object) html_escape(s) Also known as: h

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



20
21
22
# File 'lib/rss/utils.rb', line 20

def html_escape(s)
  s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
end

- (Object) new_with_value_if_need(klass, value)

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



27
28
29
30
31
32
33
# 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

- (Object) to_class_name(name)

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