Sha256: 83a2dc74aa32ff3ea40ea77d86dd56ad3ba8dba62083d8db697027db690b5de4

Contents?: true

Size: 629 Bytes

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
rubycritic-2.9.3 lib/rubycritic/core/location.rb