Sha256: 90b7e70f7944458bedf033b44405c0970971622f9761dd93702ebeb8ec8e7297

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module SlimLint
  class SourceLocation
    attr_accessor :start_line, :start_column, :last_line, :last_column, :line, :column, :length

    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

    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

    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

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slim_lint_standard-0.0.2.2 lib/slim_lint/source_location.rb
slim_lint_standard-0.0.2.1 lib/slim_lint/source_location.rb
slim_lint_standard-0.0.2 lib/slim_lint/source_location.rb
slim_lint_standard-0.0.1 lib/slim_lint/source_location.rb
slim_lint_standard-0.0.0 lib/slim_lint/source_location.rb