Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/rss
File: utils.rb
# frozen_string_literal: false
[0] Fix | Delete
module RSS
[1] Fix | Delete
[2] Fix | Delete
##
[3] Fix | Delete
# RSS::Utils is a module that holds various utility functions that are used
[4] Fix | Delete
# across many parts of the rest of the RSS library. Like most modules named
[5] Fix | Delete
# some variant of 'util', its methods are probably not particularly useful
[6] Fix | Delete
# to those who aren't developing the library itself.
[7] Fix | Delete
module Utils
[8] Fix | Delete
module_function
[9] Fix | Delete
[10] Fix | Delete
# Given a +name+ in a name_with_underscores or a name-with-dashes format,
[11] Fix | Delete
# returns the CamelCase version of +name+.
[12] Fix | Delete
#
[13] Fix | Delete
# If the +name+ is already CamelCased, nothing happens.
[14] Fix | Delete
#
[15] Fix | Delete
# Examples:
[16] Fix | Delete
#
[17] Fix | Delete
# require 'rss/utils'
[18] Fix | Delete
#
[19] Fix | Delete
# RSS::Utils.to_class_name("sample_name")
[20] Fix | Delete
# # => "SampleName"
[21] Fix | Delete
# RSS::Utils.to_class_name("with-dashes")
[22] Fix | Delete
# # => "WithDashes"
[23] Fix | Delete
# RSS::Utils.to_class_name("CamelCase")
[24] Fix | Delete
# # => "CamelCase"
[25] Fix | Delete
def to_class_name(name)
[26] Fix | Delete
name.split(/[_\-]/).collect do |part|
[27] Fix | Delete
"#{part[0, 1].upcase}#{part[1..-1]}"
[28] Fix | Delete
end.join("")
[29] Fix | Delete
end
[30] Fix | Delete
[31] Fix | Delete
# Returns an array of two elements: the filename where the calling method
[32] Fix | Delete
# is located, and the line number where it is defined.
[33] Fix | Delete
#
[34] Fix | Delete
# Takes an optional argument +i+, which specifies how many callers up the
[35] Fix | Delete
# stack to look.
[36] Fix | Delete
#
[37] Fix | Delete
# Examples:
[38] Fix | Delete
#
[39] Fix | Delete
# require 'rss/utils'
[40] Fix | Delete
#
[41] Fix | Delete
# def foo
[42] Fix | Delete
# p RSS::Utils.get_file_and_line_from_caller
[43] Fix | Delete
# p RSS::Utils.get_file_and_line_from_caller(1)
[44] Fix | Delete
# end
[45] Fix | Delete
#
[46] Fix | Delete
# def bar
[47] Fix | Delete
# foo
[48] Fix | Delete
# end
[49] Fix | Delete
#
[50] Fix | Delete
# def baz
[51] Fix | Delete
# bar
[52] Fix | Delete
# end
[53] Fix | Delete
#
[54] Fix | Delete
# baz
[55] Fix | Delete
# # => ["test.rb", 5]
[56] Fix | Delete
# # => ["test.rb", 9]
[57] Fix | Delete
#
[58] Fix | Delete
# If +i+ is not given, or is the default value of 0, it attempts to figure
[59] Fix | Delete
# out the correct value. This is useful when in combination with
[60] Fix | Delete
# instance_eval. For example:
[61] Fix | Delete
#
[62] Fix | Delete
# require 'rss/utils'
[63] Fix | Delete
#
[64] Fix | Delete
# def foo
[65] Fix | Delete
# p RSS::Utils.get_file_and_line_from_caller(1)
[66] Fix | Delete
# end
[67] Fix | Delete
#
[68] Fix | Delete
# def bar
[69] Fix | Delete
# foo
[70] Fix | Delete
# end
[71] Fix | Delete
#
[72] Fix | Delete
# instance_eval <<-RUBY, *RSS::Utils.get_file_and_line_from_caller
[73] Fix | Delete
# def baz
[74] Fix | Delete
# bar
[75] Fix | Delete
# end
[76] Fix | Delete
# RUBY
[77] Fix | Delete
#
[78] Fix | Delete
# baz
[79] Fix | Delete
#
[80] Fix | Delete
# # => ["test.rb", 8]
[81] Fix | Delete
def get_file_and_line_from_caller(i=0)
[82] Fix | Delete
file, line, = caller[i].split(':')
[83] Fix | Delete
line = line.to_i
[84] Fix | Delete
line += 1 if i.zero?
[85] Fix | Delete
[file, line]
[86] Fix | Delete
end
[87] Fix | Delete
[88] Fix | Delete
# Takes a string +s+ with some HTML in it, and escapes '&', '"', '<' and '>', by
[89] Fix | Delete
# replacing them with the appropriate entities.
[90] Fix | Delete
#
[91] Fix | Delete
# This method is also aliased to h, for convenience.
[92] Fix | Delete
#
[93] Fix | Delete
# Examples:
[94] Fix | Delete
#
[95] Fix | Delete
# require 'rss/utils'
[96] Fix | Delete
#
[97] Fix | Delete
# RSS::Utils.html_escape("Dungeons & Dragons")
[98] Fix | Delete
# # => "Dungeons &amp; Dragons"
[99] Fix | Delete
# RSS::Utils.h(">_>")
[100] Fix | Delete
# # => "&gt;_&gt;"
[101] Fix | Delete
def html_escape(s)
[102] Fix | Delete
s.to_s.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
[103] Fix | Delete
end
[104] Fix | Delete
alias h html_escape
[105] Fix | Delete
[106] Fix | Delete
# If +value+ is an instance of class +klass+, return it, else
[107] Fix | Delete
# create a new instance of +klass+ with value +value+.
[108] Fix | Delete
def new_with_value_if_need(klass, value)
[109] Fix | Delete
if value.is_a?(klass)
[110] Fix | Delete
value
[111] Fix | Delete
else
[112] Fix | Delete
klass.new(value)
[113] Fix | Delete
end
[114] Fix | Delete
end
[115] Fix | Delete
[116] Fix | Delete
# This method is used inside of several different objects to determine
[117] Fix | Delete
# if special behavior is needed in the constructor.
[118] Fix | Delete
#
[119] Fix | Delete
# Special behavior is needed if the array passed in as +args+ has
[120] Fix | Delete
# +true+ or +false+ as its value, and if the second element of +args+
[121] Fix | Delete
# is a hash.
[122] Fix | Delete
def element_initialize_arguments?(args)
[123] Fix | Delete
[true, false].include?(args[0]) and args[1].is_a?(Hash)
[124] Fix | Delete
end
[125] Fix | Delete
[126] Fix | Delete
module ExplicitCleanOther
[127] Fix | Delete
module_function
[128] Fix | Delete
def parse(value)
[129] Fix | Delete
if [true, false, nil].include?(value)
[130] Fix | Delete
value
[131] Fix | Delete
else
[132] Fix | Delete
case value.to_s
[133] Fix | Delete
when /\Aexplicit|yes|true\z/i
[134] Fix | Delete
true
[135] Fix | Delete
when /\Aclean|no|false\z/i
[136] Fix | Delete
false
[137] Fix | Delete
else
[138] Fix | Delete
nil
[139] Fix | Delete
end
[140] Fix | Delete
end
[141] Fix | Delete
end
[142] Fix | Delete
end
[143] Fix | Delete
[144] Fix | Delete
module YesOther
[145] Fix | Delete
module_function
[146] Fix | Delete
def parse(value)
[147] Fix | Delete
if [true, false].include?(value)
[148] Fix | Delete
value
[149] Fix | Delete
else
[150] Fix | Delete
/\Ayes\z/i.match(value.to_s) ? true : false
[151] Fix | Delete
end
[152] Fix | Delete
end
[153] Fix | Delete
end
[154] Fix | Delete
[155] Fix | Delete
module CSV
[156] Fix | Delete
module_function
[157] Fix | Delete
def parse(value, &block)
[158] Fix | Delete
if value.is_a?(String)
[159] Fix | Delete
value = value.strip.split(/\s*,\s*/)
[160] Fix | Delete
value = value.collect(&block) if block_given?
[161] Fix | Delete
value
[162] Fix | Delete
else
[163] Fix | Delete
value
[164] Fix | Delete
end
[165] Fix | Delete
end
[166] Fix | Delete
end
[167] Fix | Delete
[168] Fix | Delete
module InheritedReader
[169] Fix | Delete
def inherited_reader(constant_name)
[170] Fix | Delete
base_class = inherited_base
[171] Fix | Delete
result = base_class.const_get(constant_name)
[172] Fix | Delete
found_base_class = false
[173] Fix | Delete
ancestors.reverse_each do |klass|
[174] Fix | Delete
if found_base_class
[175] Fix | Delete
if klass.const_defined?(constant_name)
[176] Fix | Delete
result = yield(result, klass.const_get(constant_name))
[177] Fix | Delete
end
[178] Fix | Delete
else
[179] Fix | Delete
found_base_class = klass == base_class
[180] Fix | Delete
end
[181] Fix | Delete
end
[182] Fix | Delete
result
[183] Fix | Delete
end
[184] Fix | Delete
[185] Fix | Delete
def inherited_array_reader(constant_name)
[186] Fix | Delete
inherited_reader(constant_name) do |result, current|
[187] Fix | Delete
current + result
[188] Fix | Delete
end
[189] Fix | Delete
end
[190] Fix | Delete
[191] Fix | Delete
def inherited_hash_reader(constant_name)
[192] Fix | Delete
inherited_reader(constant_name) do |result, current|
[193] Fix | Delete
result.merge(current)
[194] Fix | Delete
end
[195] Fix | Delete
end
[196] Fix | Delete
end
[197] Fix | Delete
end
[198] Fix | Delete
end
[199] Fix | Delete
[200] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function