Sha256: 7e2993946fff064cb85c9a343921730f5383b213a9263f9446ee63df3f878dfd

Contents?: true

Size: 1.02 KB

Versions: 34

Compression:

Stored size: 1.02 KB

Contents

module SCSSLint
  # Stores a location of {Lint} in a source.
  class Location
    include Comparable

    attr_reader :line, :column, :length

    # @param line [Integer] One-based index
    # @param column [Integer] One-based index
    # @param length [Integer] Number of characters, including the first character
    def initialize(line = 1, column = 1, length = 1)
      raise ArgumentError, "Line must be more than 0, passed #{line}" if line < 1
      raise ArgumentError, "Column must be more than 0, passed #{column}" if column < 1
      raise ArgumentError, "Length must be more than 0, passed #{length}" if length < 1

      @line   = line
      @column = column
      @length = length
    end

    def ==(other)
      [:line, :column, :length].all? do |attr|
        send(attr) == other.send(attr)
      end
    end

    alias_method :eql?, :==

    def <=>(other)
      [:line, :column, :length].each do |attr|
        result = send(attr) <=> other.send(attr)
        return result unless result == 0
      end

      0
    end
  end
end

Version data entries

34 entries across 34 versions & 3 rubygems

Version Path
scss-lint-0.31.0 lib/scss_lint/location.rb
scss-lint-0.30.0 lib/scss_lint/location.rb
scss-lint-0.29.0 lib/scss_lint/location.rb
scss-lint-0.28.0 lib/scss_lint/location.rb
scss-lint-0.27.0 lib/scss_lint/location.rb
scss-lint-0.26.2 lib/scss_lint/location.rb
scss-lint-0.26.1 lib/scss_lint/location.rb
scss-lint-0.26.0 lib/scss_lint/location.rb
scss-lint-0.25.1 lib/scss_lint/location.rb
scss-lint-0.25.0 lib/scss_lint/location.rb
scss-lint-0.24.1 lib/scss_lint/location.rb
scss-lint-0.24.0 lib/scss_lint/location.rb
scss-lint-0.23.1 lib/scss_lint/location.rb
scss-lint-0.23.0 lib/scss_lint/location.rb