Sha256: c84f85bd0dd06dad728fb360ed1bc5a9b4db10b57a7d485acc33bb929b774f68

Contents?: true

Size: 629 Bytes

Versions: 6

Compression:

Stored size: 629 Bytes

Contents

require 'pathname'

module Rubycritic
  class Location
    attr_reader :pathname, :line

    def initialize(path, line)
      @pathname = Pathname.new(path)
      @line = line.to_i
    end

    def file_name
      @pathname.basename.sub_ext('').to_s
    end

    def to_s
      "#{pathname}:#{line}"
    end

    def to_h
      {
        path: pathname.to_s,
        line: line
      }
    end

    def to_json(*a)
      to_h.to_json(*a)
    end

    def ==(other)
      state == other.state
    end

    def <=>(other)
      state <=> other.state
    end

    protected

    def state
      [@pathname, @line]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubycritic-2.9.2 lib/rubycritic/core/location.rb
rubycritic-2.9.1 lib/rubycritic/core/location.rb
rubycritic-2.9.0 lib/rubycritic/core/location.rb
rubycritic-2.8.0 lib/rubycritic/core/location.rb
rubycritic-2.7.1 lib/rubycritic/core/location.rb
rubycritic-2.7.0 lib/rubycritic/core/location.rb