<commit_before>module Daru
  # rubocop:disable Style/OpMethod

  # Generic class for generating date offsets.
  class DateOffset
    # A Daru::DateOffset object is created by a passing certain options
    # to the constructor, which determine the kind of offset the object
    # will support.
    #
    # You can pass one of the following options followed by their number
    # to the DateOffset constructor:
    #
    # * :secs - Create a seconds offset
    # * :mins - Create a minutes offset
    # * :hours - Create an hours offset
    # * :days  - Create a days offset
    # * :weeks - Create a weeks offset
    # * :months - Create a months offset
    # * :years - Create a years offset
    #
    # Additionaly, passing the `:n` option will apply the offset that many times.
    #
    # @example Usage of DateOffset
    #   # Create an offset of 3 weeks.
    #   offset = Daru::DateOffset.new(weeks: 3)
    #   offset + DateTime.new(2012,5,3)
    #   #=> #<DateTime: 2012-05-24T00:00:00+00:00 ((2456072j,0s,0n),+0s,2299161j)>
    #
    #   # Create an offset of 5 hours
    #   offset = Daru::DateOffset.new(hours: 5)
    #   offset + DateTime.new(2015,3,3,23,5,1)
    #   #=> #<DateTime: 2015-03-04T04:05:01+00:00 ((2457086j,14701s,0n),+0s,2299161j)>
    #
    #   # Create an offset of 2 minutes, applied 5 times
    #   offset = Daru::DateOffset.new(mins: 2, n: 5)
    #   offset + DateTime.new(2011,5,3,3,5)
    #   #=> #<DateTime: 2011-05-03T03:15:00+00:00 ((2455685j,11700s,0n),+0s,2299161j)>
    def initialize opts={}
      n = opts[:n] || 1
      Offsets::LIST.each do |key, klass|
        if opts.key?(key)
          @offset = klass.new(n * opts[key])
          break
        end
      end

      @offset = Offsets::Day.new(7*n*opts[:weeks]) if opts[:weeks]
    end

    # Offset a DateTime forward.
    #
    # @param date_time [DateTime] A DateTime object which is to offset.
    def + date_time
      @offset + date_time
    end

    # Offset a DateTime backward.
    #
    # @param date_time [DateTime] A DateTime object which is to offset.
    def - date_time
      @offset - date_time
    end

    def -@
      NegativeDateOffset.new(self)
    end
  end

  class NegativeDateOffset
    def initialize(offset)
      @offset = offset
    end

    def + date_time
      @offset - date_time
    end

    def - date_time
      @offset + date_time
    end
  end

  module Offsets
    class DateOffsetType < DateOffset
      def initialize n=1
        @n = n
      end

      def freq_string
        (@n == 1 ? '' : @n.to_s) + self.class::FREQ
      end
    end

    # Private superclass for Offsets with equal inter-frequencies.
    # @abstract
    # @private
    class Tick < DateOffsetType
      # @method initialize
      # Initialize one of the subclasses of Tick with the number of the times
      # the offset should be applied, which is the supplied as the argument.
      #
      # @param n [Integer] The number of times an offset should be applied.

      def + date_time
        date_time + @n*multiplier
      end

      def - date_time
        date_time - @n*multiplier
      end
    end

    # Create a seconds offset
    #
    # @param n [Integer] The number of times an offset should be applied.
    # @example Create a Seconds offset
    #   offset = Daru::Offsets::Second.new(5)
    #   offset + DateTime.new(2012,5,1,4,3)
    #   #=> #<DateTime: 2012-05-01T04:03:05+00:00 ((2456049j,14585s,0n),+0s,2299161j)>
    class Second < Tick
      FREQ = 'S'.freeze

      def multiplier
        1.1574074074074073e-05<commit_msg>[ci skip] Fix the position of documents (#251)<commit_after>module Daru
  # rubocop:disable Style/OpMethod

  # Generic class for generating date offsets.
  class DateOffset
    # A Daru::DateOffset object is created by a passing certain options
    # to the constructor, which determine the kind of offset the object
    # will support.
    #
    # You can pass one of the following options followed by their number
    # to the DateOffset constructor:
    #
    # * :secs - Create a seconds offset
    # * :mins - Create a minutes offset
    # * :hours - Create an hours offset
    # * :days  - Create a days offset
    # * :weeks - Create a weeks offset
    # * :months - Create a months offset
    # * :years - Create a years offset
    #
    # Additionaly, passing the `:n` option will apply the offset that many times.
    #
    # @example Usage of DateOffset
    #   # Create an offset of 3 weeks.
    #   offset = Daru::DateOffset.new(weeks: 3)
    #   offset + DateTime.new(2012,5,3)
    #   #=> #<DateTime: 2012-05-24T00:00:00+00:00 ((2456072j,0s,0n),+0s,2299161j)>
    #
    #   # Create an offset of 5 hours
    #   offset = Daru::DateOffset.new(hours: 5)
    #   offset + DateTime.new(2015,3,3,23,5,1)
    #   #=> #<DateTime: 2015-03-04T04:05:01+00:00 ((2457086j,14701s,0n),+0s,2299161j)>
    #
    #   # Create an offset of 2 minutes, applied 5 times
    #   offset = Daru::DateOffset.new(mins: 2, n: 5)
    #   offset + DateTime.new(2011,5,3,3,5)
    #   #=> #<DateTime: 2011-05-03T03:15:00+00:00 ((2455685j,11700s,0n),+0s,2299161j)>
    def initialize opts={}
      n = opts[:n] || 1
      Offsets::LIST.each do |key, klass|
        if opts.key?(key)
          @offset = klass.new(n * opts[key])
          break
        end
      end

      @offset = Offsets::Day.new(7*n*opts[:weeks]) if opts[:weeks]
    end

    # Offset a DateTime forward.
    #
    # @param date_time [DateTime] A DateTime object which is to offset.
    def + date_time
      @offset + date_time
    end

    # Offset a DateTime backward.
    #
    # @param date_time [DateTime] A DateTime object which is to offset.
    def - date_time
      @offset - date_time
    end

    def -@
      NegativeDateOffset.new(self)
    end
  end

  class NegativeDateOffset
    def initialize(offset)
      @offset = offset
    end

    def + date_time
      @offset - date_time
    end

    def - date_time
      @offset + date_time
    end
  end

  module Offsets
    class DateOffsetType < DateOffset
      # @method initialize
      # Initialize one of the subclasses of DateOffsetType with the number of the times
      # the offset should be applied, which is the supplied as the argument.
      #
      # @param n [Integer] The number of times an offset should be applied.
      def initialize n=1
        @n = n
      end

      def freq_string
        (@n == 1 ? '' : @n.to_s) + self.class::FREQ
      end
    end

    # Private superclass for Offsets with equal inter-frequencies.
    # @abstract
    # @private
    class Tick < DateOffsetType
      def + date_time
        date_time + @n*multiplier
      end

      def - date_time
        date_time - @n*multiplier
      end
    end

    # Create a seconds offset
    #
    # @param n [Integer] The number of times an offset should be applied.
    # @example Create a Seconds offset
    #   offset = Daru::Offsets::Second.new(5)
    #   offset + DateTime.new(2012,5,1,4,3)
    #   #=> #<DateTime: 2012-05-01T04:03:05+00:00 ((2456049j,14585s,0n),+0s,2299161j)>
    class Second < Tick
      FREQ = 'S'.freeze

      def multiplier
        1.1574074074074073e-05
{'fraction_non_alphanumeric': 0.10475524475524475, 'fraction_numerical': 0.06083916083916084, 'mean_word_length': 2.333799533799534, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '4912562', 'n_tokens_mistral': 2635, 'n_tokens_neox': 2342, 'n_words': 704}