<commit_before>require 'tries/version'
require 'gem_config'

module Tries
  include GemConfig::Base

  with_configuration do
    has :on_error, classes: Proc
  end
end

class Integer
  def tries(options = {}, &block)
    attempts          = 1
    exception_classes = Array(options[:on] || StandardError)
    delay             = options[:delay]
    incremental       = options[:incremental]

    begin
      return yield
    rescue *exception_classes => exception
      next_delay = calculate_delay(delay, attempts, incremental) if delay
      Tries.configuration.on_error.call(exception, attempts, next_delay) if Tries.configuration.on_error
      options[:on_error].call(exception, attempts, next_delay) if options[:on_error]
      Kernel.sleep next_delay if delay
      retry if (attempts += 1) <= self
    end

    yield
  end

  private
  def calculate_delay(delay, attempts, incremental)
    return delay unless incremental

    delay * attempts
  end
end<commit_msg>Round delay<commit_after>require 'tries/version'
require 'gem_config'

module Tries
  include GemConfig::Base

  with_configuration do
    has :on_error, classes: Proc
  end
end

class Integer
  def tries(options = {}, &block)
    attempts          = 1
    exception_classes = Array(options[:on] || StandardError)
    delay             = options[:delay]
    incremental       = options[:incremental]

    begin
      return yield
    rescue *exception_classes => exception
      next_delay = calculate_delay(delay, attempts, incremental) if delay
      Tries.configuration.on_error.call(exception, attempts, next_delay) if Tries.configuration.on_error
      options[:on_error].call(exception, attempts, next_delay) if options[:on_error]
      Kernel.sleep next_delay if delay
      retry if (attempts += 1) <= self
    end

    yield
  end

  private
  def calculate_delay(delay, attempts, incremental)
    return delay unless incremental
    (delay * attempts * 100).round.to_f / 100
  end
end
{'fraction_non_alphanumeric': 0.08138351983723296, 'fraction_numerical': 0.00508646998982706, 'mean_word_length': 3.276086956521739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2299165', 'n_tokens_mistral': 576, 'n_tokens_neox': 548, 'n_words': 156}