Class: SlimLint::SourceLocation
- Inherits:
-
Object
- Object
- SlimLint::SourceLocation
- Defined in:
- lib/slim_lint/source_location.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#last_column ⇒ Object
Returns the value of attribute last_column.
-
#last_line ⇒ Object
Returns the value of attribute last_line.
-
#length ⇒ Object
Returns the value of attribute length.
-
#line ⇒ Object
Returns the value of attribute line.
-
#start_column ⇒ Object
Returns the value of attribute start_column.
-
#start_line ⇒ Object
Returns the value of attribute start_line.
Class Method Summary collapse
Instance Method Summary collapse
- #adjust(line: 0, column: 0) ⇒ Object
- #as_json ⇒ Object
-
#initialize(start_line: nil, start_column: nil, last_line: nil, last_column: nil, length: nil) ⇒ SourceLocation
constructor
A new instance of SourceLocation.
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
#column ⇒ Object
Returns the value of attribute column.
3 4 5 |
# File 'lib/slim_lint/source_location.rb', line 3 def column @column end |
#last_column ⇒ Object
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_line ⇒ Object
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 |
#length ⇒ Object
Returns the value of attribute length.
3 4 5 |
# File 'lib/slim_lint/source_location.rb', line 3 def length @length end |
#line ⇒ Object
Returns the value of attribute line.
3 4 5 |
# File 'lib/slim_lint/source_location.rb', line 3 def line @line end |
#start_column ⇒ Object
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_line ⇒ Object
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_json ⇒ Object
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 |