<commit_before>unless Range.method_defined? :size
  # A horrible monkeypatch for 1.9.3. It should be robust yet
  # may be slow due to creation of a Enumerator.
  class Range
    def size
      self.step.size
    end
  end
end

module Parser

  class Diagnostic
    LEVELS = [:note, :warning, :error, :fatal].freeze

    attr_reader :source_file
    attr_reader :level, :message, :ranges, :line

    def initialize(level, message, source_file, ranges)
      unless LEVELS.include?(level)
        raise ArgumentError,
              "Diagnostic#level must be one of #{LEVELS.join(', ')}; " \
              "#{level.inspect} provided."
      end

      @level       = level
      @message     = message.to_s.dup.freeze
      @source_file = source_file

      # Array(...) converts a range to an array of elements.
      # We probably need an #is_a?(Range) check here, but I dislike
      # type snooping in Ruby.
      unless ranges.respond_to? :to_ary
        ranges = [ranges]
      end

      ranges       = ranges.sort_by &:begin

      # Refactor this?
      positions    = ranges.map { |r| [r.begin, r.end] }.reduce([], :+)
      unique_lines = positions.map { |pos| @source_file.position_to_line(pos) }.uniq

      if unique_lines.count > 1
        raise ArgumentError,
              "Cannot create a Diagnostic which spans over multiple source lines."
      end

      @ranges      = ranges.dup.freeze
      @line        = unique_lines.first

      freeze
    end<commit_msg>Add optinal parentheses for method calls with arguments<commit_after>unless Range.method_defined? :size
  # A horrible monkeypatch for 1.9.3. It should be robust yet
  # may be slow due to creation of a Enumerator.
  class Range
    def size
      self.step.size
    end
  end
end

module Parser

  class Diagnostic
    LEVELS = [:note, :warning, :error, :fatal].freeze

    attr_reader :source_file
    attr_reader :level, :message, :ranges, :line

    def initialize(level, message, source_file, ranges)
      unless LEVELS.include?(level)
        raise ArgumentError,
              "Diagnostic#level must be one of #{LEVELS.join(', ')}; " \
              "#{level.inspect} provided."
      end

      @level       = level
      @message     = message.to_s.dup.freeze
      @source_file = source_file

      # Array(...) converts a range to an array of elements.
      # We probably need an #is_a?(Range) check here, but I dislike
      # type snooping in Ruby.
      unless ranges.respond_to?(:to_ary)
        ranges = [ranges]
      end

      ranges       = ranges.sort_by(&:begin)

      # Refactor this?
      positions    = ranges.map { |r| [r.begin, r.end] }.reduce([], :+)
      unique_lines = positions.map { |pos| @source_file.position_to_line(pos) }.uniq

      if unique_lines.count > 1
        raise ArgumentError,
              "Cannot create a Diagnostic which spans over multiple source lines."
      end

      @ranges      = ranges.dup.freeze
      @line        = unique_lines.first

      freeze
    end
{'fraction_non_alphanumeric': 0.09653794940079893, 'fraction_numerical': 0.002663115845539281, 'mean_word_length': 2.2451403887688985, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4705333', 'n_tokens_mistral': 943, 'n_tokens_neox': 906, 'n_words': 280}