<commit_before>module Overlaps
  class PseudoRange
    attr_accessor :start_point, :end_point, :id

    def initialize(range, accessors = {})
      verify_input(range, accessors)
      ensure_points_are_same_class
      build
    end

    def points
      [@start_point, @end_point]
    end

    def range
      (@start_point.value..@end_point.value)
    end

    def type
      @start_point.value.class
    end

    private

    def verify_input(range, accessors)
      if range.is_a?(Range)
        @start_point = range.first
        @end_point = range.last
        @id = accessors.fetch(:index) { raise ArgumentError, 'Must provide the :index key/value option when given a Range object.' }
      else
        @start_point = range.send accessors.fetch(:start) { raise ArgumentError, 'Must provide the :start key/value option when given a non-Range object.' }
        @end_point = range.send accessors.fetch(:end) { raise ArgumentError, 'Must provide the :end key/value option when given a non-Range object.' }
        @id = determine_id(range, accessors)
      end
    end

    def determine_id(range, accessors)
      method = accessors.fetch(:id)
      if method && range.respond_to?(method)
        range.send(method)
      elsif range.respond_to?(:id)
        range.send(:id)
      else
        accessors.fetch(:id)
      end
    end

    def ensure_points_are_same_class
      raise TypeError, 'The start and end points for a PseudoRange must be of the same class.' unless start_point.class == end_point.class
    end

    def build
      @start_point = StartPoint.new(@start_point, @id)
      @end_point = EndPoint.new(@end_point, @id)
    end
  end
end<commit_msg>Fix to ensure that non-Range input provided without an explicit :id attribute will use the non-Range's index as found in the original input array for the id.<commit_after>module Overlaps
  class PseudoRange
    attr_accessor :start_point, :end_point, :id

    def initialize(range, accessors = {})
      verify_input(range, accessors)
      ensure_points_are_same_class
      build
    end

    def points
      [@start_point, @end_point]
    end

    def range
      (@start_point.value..@end_point.value)
    end

    def type
      @start_point.value.class
    end

    private

    def verify_input(range, accessors)
      if range.is_a?(Range)
        @start_point = range.first
        @end_point = range.last
        @id = accessors.fetch(:index) { raise ArgumentError, 'Must provide the :index key/value option when given a Range object.' }
      else
        @start_point = range.send accessors.fetch(:start) { raise ArgumentError, 'Must provide the :start key/value option when given a non-Range object.' }
        @end_point = range.send accessors.fetch(:end) { raise ArgumentError, 'Must provide the :end key/value option when given a non-Range object.' }
        @id = determine_id(range, accessors)
      end
    end

    def determine_id(range, accessors)
      method = accessors[:id]
      if method && range.respond_to?(method)
        range.send(method)
      elsif range.respond_to?(:id)
        range.send(:id)
      else
        accessors.fetch(:index)
      end
    end

    def ensure_points_are_same_class
      raise TypeError, 'The start and end points for a PseudoRange must be of the same class.' unless start_point.class == end_point.class
    end

    def build
      @start_point = StartPoint.new(@start_point, @id)
      @end_point = EndPoint.new(@end_point, @id)
    end
  end
end
{'fraction_non_alphanumeric': 0.08775451677659879, 'fraction_numerical': 0.0, 'mean_word_length': 2.7465091299677766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5910378', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1042, 'n_words': 307}