module StringRefinement

@private

Public Instance Methods

/(path_part) click to toggle source
# File lib/robust_excel_ole/general.rb, line 92
def / path_part
  return path_part if empty?
  return self if path_part.nil? || path_part.empty?
  begin
    path_part = path_part.strip
    (path_part  =~ /^(\/|([A-Z]:\/))/i) ? path_part : (chomp('/') + '/' + path_part)
  rescue TypeError
    raise TypeError, "Only strings can be parts of paths (given: #{path_part.inspect} of class #{path_part.class})"
  end
end
constantize() click to toggle source

taken from apidock.com/rails/ActiveSupport/Inflector/constantize File activesupport/lib/active_support/inflector/methods.rb, line 226

# File lib/robust_excel_ole/general.rb, line 120
def constantize # (camel_cased_word)
  names = split('::')

  # Trigger a builtin NameError exception including the ill-formed constant in the message.
  Object.const_get(self) if names.empty?

  # Remove the first blank element in case of '::ClassName' notation.
  names.shift if names.size > 1 && names.first.empty?

  names.inject(Object) do |constant, name|
    if constant == Object
      constant.const_get(name)
    else
      candidate = constant.const_get(name)
      next candidate if constant.const_defined?(name)
      next candidate unless Object.const_defined?(name)

      # Go down the ancestors to check it it's owned
      # directly before we reach Object or the end of ancestors.
      constant = constant.ancestors.inject do |const, ancestor|
        break const    if ancestor == Object
        break ancestor if ancestor.const_defined?(name)

        const
      end

      # owner is in Object, so raise
      constant.const_get(name)
    end
  end
end
replace_umlauts() click to toggle source
# File lib/robust_excel_ole/general.rb, line 103
def replace_umlauts
  TRANSLATION_TABLE.inject(encode('utf-8')) { |word,(umlaut, replacement)| word.gsub(umlaut, replacement) }
end
underscore() click to toggle source

taken from apidock.com/rails/ActiveSupport/Inflector/underscore

# File lib/robust_excel_ole/general.rb, line 109
def underscore
  word = gsub('::', '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!('-', '_')
  word.downcase!
  word
end