Class: SCSSLint::Location

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/scss_lint/location.rb

Overview

Stores a location of Lint in a source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line = 1, column = 1, length = 1) ⇒ Location

Returns a new instance of Location.

Parameters:

  • line (Integer) (defaults to: 1)

    One-based index

  • column (Integer) (defaults to: 1)

    One-based index

  • length (Integer) (defaults to: 1)

    Number of characters, including the first character

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
# File 'lib/scss_lint/location.rb', line 11

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

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/scss_lint/location.rb', line 6

def column
  @column
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/scss_lint/location.rb', line 6

def length
  @length
end

#lineObject (readonly)

Returns the value of attribute line.



6
7
8
# File 'lib/scss_lint/location.rb', line 6

def line
  @line
end

Instance Method Details

#<=>(other) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/scss_lint/location.rb', line 29

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

  0
end

#==(other) ⇒ Object Also known as: eql?



21
22
23
24
25
# File 'lib/scss_lint/location.rb', line 21

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