class String

String class method additions

Public Instance Methods

join_url(url) click to toggle source
# File lib/automation_object/helpers/string.rb, line 15
def join_url(url)
  full_url = chomp('/') + url.reverse.chomp('/').reverse
  full_url
end
pascalize() click to toggle source

Convert self to pascal case

# File lib/automation_object/helpers/string.rb, line 21
def pascalize
  return self if self !~ /_/ && self =~ /[A-Z]+.*/
  split('_').map(&:capitalize).join
end
to_underscore() click to toggle source

Convert string to underscore @return [String] underscored string

# File lib/automation_object/helpers/string.rb, line 35
def to_underscore
  dup.tap(&:to_underscore!)
end
to_underscore!() click to toggle source

Convert string to underscore @return [String] underscored self string

# File lib/automation_object/helpers/string.rb, line 28
def to_underscore!
  gsub!(/(.)([A-Z])/, '\1_\2')
  downcase!
end
valid_url?() click to toggle source

Test whether a string is a valid url or not @return [Boolean]

# File lib/automation_object/helpers/string.rb, line 7
def valid_url?
  uri = URI.parse(self)
  return true if uri.is_a?(URI::HTTP)
  return !(self =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix).nil?
rescue URI::InvalidURIError
  return false
end