<commit_before>require 'spreadsheet'

class Worksheet < ::Spreadsheet::Excel::Worksheet
  def each_with_index(*args)
    return enum_for(:each_with_index, *args) unless block_given?

    index = 0
    each(*args) do |v|
      yield v, index
      index += 1
    end
  end
end

# ruby-spreadsheet has a font object so we're extending it
# with our own functionality but still providing full access
# to the user for other font information
class ::Spreadsheet::Font
  def bold?(*args)
    #From ruby-spreadsheet doc: 100 <= weight <= 1000, bold => 700, normal => 400
    weight == 700
  end

  def italic?
    italic
  end

  def underline?
    underline != :none
  end
end

# Class for handling Excel-Spreadsheets
class Roo::Excel < Roo::Base
  FORMULAS_MESSAGE = 'the spreadsheet gem does not support forumulas, so roo can not.'

  attr_reader :workbook

  # Creates a new Excel spreadsheet object.
  # Parameter packed: :zip - File is a zip-file
  # Parameter mode: 'rb+' - Mode of the xls file reader
  # Parameter input_encoding: Encoding:: - Encoding of the embeded binary data (default nil)
  # Parameter output_encoding: Encoding:: - Encoding of the internal string structures
  def initialize(filename, options = {}, deprecated_file_warning = nil)
    unless Hash === options
      warn 'Supplying `packed` or `file_warning` as separate arguments to `Roo::Excel.new` is deprecated. Use an options hash instead.'
      options = { packed: options }
    end

    packed = options[:packed]
    file_warning = options[:file_warning] || deprecated_file_warning || :error
    mode = options[:mode] || 'rb+'
    @input_encoding = options[:input_encoding]
    @output_encoding = options[:output_encoding] || Encoding::UTF_8

    file_type_check(filename, '.xls', 'an Excel', file_warning, packed)
    make_tmpdir do |tmpdir|
      filename = download_uri(filename, tmpdir) if uri?(filename)
      filename = open_from_stream(filename[7..-1], tmpdir) if filename.is_a?(::String) && filename.start_with?('stream:')
      filename = unzip(filename, tmpdir) if packed == :zip

      @filename = filename
      unless File.file?(@filename)
        fail IOError, "file #{@filename} does not exist"
      end<commit_msg>Added IOStream support to xls parsing<commit_after>require 'spreadsheet'

class Worksheet < ::Spreadsheet::Excel::Worksheet
  def each_with_index(*args)
    return enum_for(:each_with_index, *args) unless block_given?

    index = 0
    each(*args) do |v|
      yield v, index
      index += 1
    end
  end
end

# ruby-spreadsheet has a font object so we're extending it
# with our own functionality but still providing full access
# to the user for other font information
class ::Spreadsheet::Font
  def bold?(*args)
    #From ruby-spreadsheet doc: 100 <= weight <= 1000, bold => 700, normal => 400
    weight == 700
  end

  def italic?
    italic
  end

  def underline?
    underline != :none
  end
end

# Class for handling Excel-Spreadsheets
class Roo::Excel < Roo::Base
  FORMULAS_MESSAGE = 'the spreadsheet gem does not support forumulas, so roo can not.'

  attr_reader :workbook

  # Creates a new Excel spreadsheet object.
  # Parameter packed: :zip - File is a zip-file
  # Parameter mode: 'rb+' - Mode of the xls file reader
  # Parameter input_encoding: Encoding:: - Encoding of the embeded binary data (default nil)
  # Parameter output_encoding: Encoding:: - Encoding of the internal string structures
  def initialize(filename, options = {}, deprecated_file_warning = nil)
    unless Hash === options
      warn 'Supplying `packed` or `file_warning` as separate arguments to `Roo::Excel.new` is deprecated. Use an options hash instead.'
      options = { packed: options }
    end

    packed = options[:packed]
    file_warning = options[:file_warning] || deprecated_file_warning || :error
    mode = options[:mode] || 'rb+'
    @input_encoding = options[:input_encoding]
    @output_encoding = options[:output_encoding] || Encoding::UTF_8

    file_type_check(filename, '.xls', 'an Excel', file_warning, packed)
    make_tmpdir do |tmpdir|
      filename = download_uri(filename, tmpdir) if uri?(filename)
      filename = open_from_stream(filename[7..-1], tmpdir) if filename.is_a?(::String) && filename.start_with?('stream:')
      filename = unzip(filename, tmpdir) if packed == :zip

      @filename = filename
      unless @filename.respond_to? :seek || File.file?(@filename)
        fail IOError, "file #{@filename} does not exist"
      end
{'fraction_non_alphanumeric': 0.10404108059834785, 'fraction_numerical': 0.009377093101138647, 'mean_word_length': 3.765957446808511, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5784195', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1303, 'n_words': 448}