Sha256: 0df8b17716a356cef81bfdf04c23b08962b22d4ebcac5c6bf28b815d8ea20308

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 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 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

16 entries across 16 versions & 1 rubygems

Version Path
scss_lint-0.55.0 lib/scss_lint/location.rb
scss_lint-0.54.0 lib/scss_lint/location.rb
scss_lint-0.53.0 lib/scss_lint/location.rb
scss_lint-0.52.0 lib/scss_lint/location.rb
scss_lint-0.51.0 lib/scss_lint/location.rb
scss_lint-0.50.3 lib/scss_lint/location.rb
scss_lint-0.50.2 lib/scss_lint/location.rb
scss_lint-0.50.1 lib/scss_lint/location.rb
scss_lint-0.50.0 lib/scss_lint/location.rb
scss_lint-0.49.0 lib/scss_lint/location.rb
scss_lint-0.48.0 lib/scss_lint/location.rb
scss_lint-0.47.1 lib/scss_lint/location.rb
scss_lint-0.47.0 lib/scss_lint/location.rb
scss_lint-0.46.0 lib/scss_lint/location.rb
scss_lint-0.45.0 lib/scss_lint/location.rb
scss_lint-0.44.0 lib/scss_lint/location.rb