Class: SlimLint::SourceLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/slim_lint/source_location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line: nil, start_column: nil, last_line: nil, last_column: nil, length: nil) ⇒ SourceLocation



15
16
17
18
19
20
21
# File 'lib/slim_lint/source_location.rb', line 15

def initialize(start_line: nil, start_column: nil, last_line: nil, last_column: nil, length: nil)
  @start_line = @line = start_line
  @start_column = @column = start_column
  @last_line = last_line || @start_line
  @last_column = last_column || @start_column
  @length = length || (start_line == last_line ? last_column - start_column : nil)
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def column
  @column
end

#last_columnObject

Returns the value of attribute last_column.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def last_column
  @last_column
end

#last_lineObject

Returns the value of attribute last_line.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def last_line
  @last_line
end

#lengthObject

Returns the value of attribute length.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def length
  @length
end

#lineObject

Returns the value of attribute line.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def line
  @line
end

#start_columnObject

Returns the value of attribute start_column.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def start_column
  @start_column
end

#start_lineObject

Returns the value of attribute start_line.



3
4
5
# File 'lib/slim_lint/source_location.rb', line 3

def start_line
  @start_line
end

Class Method Details

.merge(start, finish, length:) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/slim_lint/source_location.rb', line 5

def self.merge(start, finish, length:)
  new(
    start_line: start.start_line,
    start_column: start.start_column,
    last_line: finish.start_line,
    last_column: finish.start_column,
    length: length
  )
end

Instance Method Details

#adjust(line: 0, column: 0) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/slim_lint/source_location.rb', line 35

def adjust(line: 0, column: 0)
  self.class.new(
    length: @length,
    start_line: @start_line + line,
    start_column: @start_column + column,
    last_line: @last_line + line,
    last_column: @last_column + column
  )
end

#as_jsonObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/slim_lint/source_location.rb', line 23

def as_json
  {
    line: line,
    column: column,
    length: length,
    start_line: start_line,
    start_column: start_column,
    last_line: last_line,
    last_column: last_column
  }.compact
end