Sha256: a6652bba336ef281dfc20a80d027bc81ca0441635a5c9a0178c09e6379945775

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module I18n::Tasks::Scanners
  # The occurrence of some key in a file.
  #
  # @note This is a value type. Equality and hash code are determined from the attributes.
  class Occurrence
    # @return [String] source path relative to the current working directory.
    attr_reader :path

    # @return [Fixnum] count of characters in the file before the occurrence.
    attr_reader :pos

    # @return [Fixnum] line number of the occurrence, counting from 1.
    attr_reader :line_num

    # @return [Fixnum] position of the start of the occurrence in the line, counting from 1.
    attr_reader :line_pos

    # @return [String] the line of the occurrence, excluding the last LF or CRLF.
    attr_reader :line

    # @param path     [String]
    # @param pos      [Fixnum]
    # @param line_num [Fixnum]
    # @param line_pos [Fixnum]
    # @param line     [String]
    def initialize(path:, pos:, line_num:, line_pos:, line:)
      @path     = path
      @pos      = pos
      @line_num = line_num
      @line_pos = line_pos
      @line     = line
    end

    def inspect
      "Occurrence(#{@path}:#{@line_num}:#{@line_pos}:(#{@pos})"
    end

    def ==(other)
      other.path == @path && other.pos == @pos && other.line_num == @line_num && other.line == @line
    end

    def eql?(other)
      self == other
    end

    def hash
      [@path, @pos, @line_num, @line_pos, @line].hash
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n-tasks-0.9.0.rc1 lib/i18n/tasks/scanners/occurence.rb