2004-01-27 22:46:13 -05:00
|
|
|
module RSS
|
2004-10-16 00:51:15 -04:00
|
|
|
module Utils
|
2005-02-03 10:31:57 -05:00
|
|
|
module_function
|
2008-06-29 05:02:32 -04:00
|
|
|
|
|
|
|
# Convert a name_with_underscores to CamelCase.
|
2005-02-03 10:31:57 -05:00
|
|
|
def to_class_name(name)
|
2007-08-04 23:03:05 -04:00
|
|
|
name.split(/[_\-]/).collect do |part|
|
2005-02-03 10:31:57 -05:00
|
|
|
"#{part[0, 1].upcase}#{part[1..-1]}"
|
|
|
|
end.join("")
|
|
|
|
end
|
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def get_file_and_line_from_caller(i=0)
|
|
|
|
file, line, = caller[i].split(':')
|
2007-08-04 23:03:05 -04:00
|
|
|
line = line.to_i
|
|
|
|
line += 1 if i.zero?
|
|
|
|
[file, line]
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2008-06-29 05:02:32 -04:00
|
|
|
# escape '&', '"', '<' and '>' for use in HTML.
|
2004-10-16 00:51:15 -04:00
|
|
|
def html_escape(s)
|
|
|
|
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
|
|
|
end
|
|
|
|
alias h html_escape
|
|
|
|
|
2008-06-29 05:02:32 -04:00
|
|
|
# If +value+ is an instance of class +klass+, return it, else
|
|
|
|
# create a new instance of +klass+ with value +value+.
|
2005-04-05 02:42:03 -04:00
|
|
|
def new_with_value_if_need(klass, value)
|
|
|
|
if value.is_a?(klass)
|
|
|
|
value
|
|
|
|
else
|
|
|
|
klass.new(value)
|
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
def element_initialize_arguments?(args)
|
|
|
|
[true, false].include?(args[0]) and args[1].is_a?(Hash)
|
|
|
|
end
|
2007-08-04 23:03:05 -04:00
|
|
|
|
|
|
|
module YesCleanOther
|
|
|
|
module_function
|
|
|
|
def parse(value)
|
|
|
|
if [true, false, nil].include?(value)
|
|
|
|
value
|
|
|
|
else
|
|
|
|
case value.to_s
|
|
|
|
when /\Ayes\z/i
|
|
|
|
true
|
|
|
|
when /\Aclean\z/i
|
|
|
|
false
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module YesOther
|
|
|
|
module_function
|
|
|
|
def parse(value)
|
|
|
|
if [true, false].include?(value)
|
|
|
|
value
|
|
|
|
else
|
|
|
|
/\Ayes\z/i.match(value.to_s) ? true : false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module CSV
|
|
|
|
module_function
|
2007-09-15 00:41:28 -04:00
|
|
|
def parse(value, &block)
|
2007-08-04 23:03:05 -04:00
|
|
|
if value.is_a?(String)
|
2007-09-15 00:41:28 -04:00
|
|
|
value = value.strip.split(/\s*,\s*/)
|
|
|
|
value = value.collect(&block) if block_given?
|
|
|
|
value
|
2007-08-04 23:03:05 -04:00
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module InheritedReader
|
|
|
|
def inherited_reader(constant_name)
|
|
|
|
base_class = inherited_base
|
|
|
|
result = base_class.const_get(constant_name)
|
|
|
|
found_base_class = false
|
|
|
|
ancestors.reverse_each do |klass|
|
|
|
|
if found_base_class
|
|
|
|
if klass.const_defined?(constant_name)
|
|
|
|
result = yield(result, klass.const_get(constant_name))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
found_base_class = klass == base_class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def inherited_array_reader(constant_name)
|
|
|
|
inherited_reader(constant_name) do |result, current|
|
|
|
|
current + result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inherited_hash_reader(constant_name)
|
|
|
|
inherited_reader(constant_name) do |result, current|
|
|
|
|
result.merge(current)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
end
|