<commit_before># coding: utf-8

class PDF::Reader
  class TextRun < Struct.new(:x, :y, :width, :text)
    include Comparable

    MERGE_LIMIT = 12

    alias :to_s :text

    # Allows collections of TextRun objects to be sorted. They will be sorted
    # in order of their position on a cartesian plain - Top Left to Bottom Right
    def <=>(other)
      if x == other.x && y == other.y
        0
      elsif y < other.y
        1
      elsif y > other.y
        -1
      elsif x < other.x
        -1
      elsif x > other.x
        1
      end
    end

    def endx
      x + width
    end

    def mergable?(other)
      y.to_i == other.y.to_i && Range.new(endx - 3, endx + MERGE_LIMIT).include?(other.x)
    end

    def +(other)
      raise ArgumentError, "#{other} cannot be merged with this run" unless mergable?(other)

      TextRun.new(x, y, other.endx - x, text + other.text)
    end

    def inspect
      "#{text} w:#{width} @#{x},#{y}"
    end
  end
end<commit_msg>convert TextRun from a struct to a class<commit_after># coding: utf-8

class PDF::Reader
  class TextRun
    include Comparable

    MERGE_LIMIT = 12

    attr_reader :x, :y, :width, :text

    alias :to_s :text

    def initialize(x, y, width, text)
      @x = x
      @y = y
      @width = width
      @text = text
    end

    # Allows collections of TextRun objects to be sorted. They will be sorted
    # in order of their position on a cartesian plain - Top Left to Bottom Right
    def <=>(other)
      if x == other.x && y == other.y
        0
      elsif y < other.y
        1
      elsif y > other.y
        -1
      elsif x < other.x
        -1
      elsif x > other.x
        1
      end
    end

    def endx
      @endx ||= x + width
    end

    def mergable?(other)
      y.to_i == other.y.to_i && mergable_range.include?(other.x)
    end

    def +(other)
      raise ArgumentError, "#{other} cannot be merged with this run" unless mergable?(other)

      TextRun.new(x, y, other.endx - x, text + other.text)
    end

    def inspect
      "#{text} w:#{width} @#{x},#{y}"
    end

    private

    def mergable_range
      @mergable_range ||= Range.new(endx - 3, endx + MERGE_LIMIT)
    end
  end
end
{'fraction_non_alphanumeric': 0.10797266514806378, 'fraction_numerical': 0.008200455580865604, 'mean_word_length': 1.9047619047619047, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '1652232', 'n_tokens_mistral': 780, 'n_tokens_neox': 757, 'n_words': 254}