<commit_before># -*- coding: utf-8 -*-
require 'pathname'

module ToReoRefinement

  refine WIN32OLE do

    # type-lifting WIN32OLE objects to RobustExcelOle objects
    def to_reo
      General.class2method.each do |element|
        classname = element.first.first
        method = element.first.last
        begin
          self.send(method)
          if classname == RobustExcelOle::Range && self.Rows.Count == 1 && self.Columns.Count == 1
            return Cell.new(self, self.Parent)
          else
            return classname.new(self)
          end
        rescue
          next
        end
      end
      raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
    end

  end

end

# @private
class WIN32OLE

  include Enumerable

end

# @private
module FindAllIndicesRefinement

  refine Array do

    def find_all_indices elem
      elem = elem.encode('utf-8') if elem.respond_to?(:gsub)      
      found, index, result = -1, -1, []
      while found
        found = self[index+1..-1].index(elem)
        if found
          index = index + found + 1
          result << index
        end
      end
      result
    end

  end

end


# @private
module StringRefinement

  refine String do

    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

    TRANSLATION_TABLE = {
      'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue',
      'ß' => 'ss', '²' => '2', '³' => '3'
    }

    def replace_umlauts
      TRANSLATION_TABLE.inject(encode('utf-8')) { |word,(umlaut, replacement)| word.gsub(umlaut, replacement) }
    end


    # taken from http://apidock.com/rails/ActiveSupport/Inflector/underscore
    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

    # taken from http://apidock.com/rails/ActiveSupport/Inflector/constantize
    # File activesupport/lib/active_support/inflector/methods.rb, line 226<commit_msg>constant definition<commit_after># -*- coding: utf-8 -*-
require 'pathname'

module ToReoRefinement

  refine WIN32OLE do

    # type-lifting WIN32OLE objects to RobustExcelOle objects
    def to_reo
      General.class2method.each do |element|
        classname = element.first.first
        method = element.first.last
        begin
          self.send(method)
          if classname == RobustExcelOle::Range && self.Rows.Count == 1 && self.Columns.Count == 1
            return Cell.new(self, self.Parent)
          else
            return classname.new(self)
          end
        rescue
          next
        end
      end
      raise TypeREOError, "given object cannot be type-lifted to a RobustExcelOle object"
    end

  end

end

# @private
class WIN32OLE

  include Enumerable

end

# @private
module FindAllIndicesRefinement

  refine Array do

    def find_all_indices elem
      elem = elem.encode('utf-8') if elem.respond_to?(:gsub)      
      found, index, result = -1, -1, []
      while found
        found = self[index+1..-1].index(elem)
        if found
          index = index + found + 1
          result << index
        end
      end
      result
    end

  end

end

TRANSLATION_TABLE = {
      'ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'Ä' => 'Ae', 'Ö' => 'Oe', 'Ü' => 'Ue',
      'ß' => 'ss', '²' => '2', '³' => '3'
    }

# @private
module StringRefinement

  refine String do

    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    

    def replace_umlauts
      TRANSLATION_TABLE.inject(encode('utf-8')) { |word,(umlaut, replacement)| word.gsub(umlaut, replacement) }
    end


    # taken from http://apidock.com/rails/ActiveSupport/Inflector/underscore
    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

    # taken from http://apidock.com/rails/ActiveSupport/Inflector/constantize
    # File activesupport/lib/active_support/inflector/methods.rb, line 226
{'fraction_non_alphanumeric': 0.14092140921409213, 'fraction_numerical': 0.01084010840108401, 'mean_word_length': 2.209364548494983, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '339863', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1626, 'n_words': 384}