module SSCBot::Util

Your typical utility methods that should be moved into a separate Gem one day…

@author Jonathan Bradley Whited @since 0.1.0

Constants

OS
RUBY_ENGINE

Public Class Methods

os(host_os=RbConfig::CONFIG['host_os']) click to toggle source
# File lib/ssc.bot/util.rb, line 23
def self.os(host_os=RbConfig::CONFIG['host_os'])
  os = :unknown

  case host_os
  when /darwin/i
    os = :macos
  # I think 'cygwin' here makes sense.
  when /linux|arch|cygwin/i
    os = :linux
  else
    # Here so that 'win' doesn't capture 'darwin'.
    case host_os
    # windows|mswin|bccwin|wince
    when /win|mingw|emx/i
      os = :windows
    end
  end

  return os
end
quote_str_or_regex(value) click to toggle source
# File lib/ssc.bot/util.rb, line 45
def self.quote_str_or_regex(value)
  if value.respond_to?(:source)
    return value.source.gsub(' ','\\ ') # For //x
  else
    return Regexp.quote(value)
  end
end
ruby_engine() click to toggle source
# File lib/ssc.bot/util.rb, line 53
def self.ruby_engine
  engines = [
    defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : nil,
    RbConfig::CONFIG['ruby_install_name'],
    RbConfig::CONFIG['rubyw_install_name'],
    RbConfig::CONFIG['RUBY_INSTALL_NAME'],
    RbConfig::CONFIG['RUBYW_INSTALL_NAME'],
    RbConfig.ruby,
  ].join('|').downcase

  if engines.include?('jruby')
    return :jruby
  elsif engines.include?('truffleruby')
    return :truffleruby
  end

  return :ruby
end
u_blank?(str) click to toggle source

Universally, is str empty after stripping or nil?

# File lib/ssc.bot/util.rb, line 74
def self.u_blank?(str)
  return str.nil? || str.empty? || u_strip(str).empty?
end
u_lstrip(str) click to toggle source

Universally, left strip str's leading (head) space.

# File lib/ssc.bot/util.rb, line 79
def self.u_lstrip(str)
  return nil if str.nil?
  return str.gsub(/\A[[:space:]]+/,'')
end
u_rstrip(str) click to toggle source

Universally, right strip str's trailing (tail) space.

# File lib/ssc.bot/util.rb, line 85
def self.u_rstrip(str)
  return nil if str.nil?
  return str.gsub(/[[:space:]]+\z/,'')
end
u_strip(str) click to toggle source

Universally, strip str's space.

# File lib/ssc.bot/util.rb, line 91
def self.u_strip(str)
  return nil if str.nil?
  return str.gsub(/\A[[:space:]]+|[[:space:]]+\z/,'')
end