Class: I18n::Tasks::Scanners::Results::Occurrence

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/tasks/scanners/results/occurrence.rb

Overview

Note:

This is a value type. Equality and hash code are determined from the attributes.

The occurrence of some key in a file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, pos:, line_num:, line_pos:, line:, raw_key: nil, default_arg: nil) ⇒ Occurrence

rubocop:disable Metrics/ParameterLists

Parameters:

  • path (String)
  • pos (Integer)
  • line_num (Integer)
  • line_pos (Integer)
  • line (String)
  • raw_key (String, nil) (defaults to: nil)
  • default_arg (String, nil) (defaults to: nil)


39
40
41
42
43
44
45
46
47
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 39

def initialize(path:, pos:, line_num:, line_pos:, line:, raw_key: nil, default_arg: nil)
  @path        = path
  @pos         = pos
  @line_num    = line_num
  @line_pos    = line_pos
  @line        = line
  @raw_key     = raw_key
  @default_arg = default_arg
end

Instance Attribute Details

#default_argString? (readonly)

Returns the value of the ‘default:` argument of the translate call.

Returns:

  • (String, nil)

    the value of the ‘default:` argument of the translate call.



26
27
28
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 26

def default_arg
  @default_arg
end

#lineString (readonly)

Returns the line of the occurrence, excluding the last LF or CRLF.

Returns:

  • (String)

    the line of the occurrence, excluding the last LF or CRLF.



23
24
25
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 23

def line
  @line
end

#line_numInteger (readonly)

Returns line number of the occurrence, counting from 1.

Returns:

  • (Integer)

    line number of the occurrence, counting from 1.



17
18
19
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 17

def line_num
  @line_num
end

#line_posInteger (readonly)

Returns position of the start of the occurrence in the line, counting from 1.

Returns:

  • (Integer)

    position of the start of the occurrence in the line, counting from 1.



20
21
22
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 20

def line_pos
  @line_pos
end

#pathString (readonly)

Returns source path relative to the current working directory.

Returns:

  • (String)

    source path relative to the current working directory.



11
12
13
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 11

def path
  @path
end

#posInteger (readonly)

Returns count of characters in the file before the occurrence.

Returns:

  • (Integer)

    count of characters in the file before the occurrence.



14
15
16
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 14

def pos
  @pos
end

#raw_keyString?

Returns the raw key (for relative keys and references).

Returns:

  • (String, nil)

    the raw key (for relative keys and references)



29
30
31
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 29

def raw_key
  @raw_key
end

Class Method Details

.from_range(raw_key:, range:, default_arg: nil) ⇒ Results::Occurrence

Parameters:

  • raw_key (String)
  • range (Parser::Source::Range)
  • default_arg (String, nil) (defaults to: nil)

Returns:



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 71

def self.from_range(raw_key:, range:, default_arg: nil)
  Occurrence.new(
    path: range.source_buffer.name,
    pos: range.begin_pos,
    line_num: range.line,
    line_pos: range.column,
    line: range.source_line,
    raw_key: raw_key,
    default_arg: default_arg
  )
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 54

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 59

def eql?(other)
  self == other
end

#hashObject



63
64
65
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 63

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

#inspectObject

rubocop:enable Metrics/ParameterLists



50
51
52
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 50

def inspect
  "Occurrence(#{@path}:#{@line_num}, line_pos: #{@line_pos}, pos: #{@pos}, raw_key: #{@raw_key}, default_arg: #{@default_arg}, line: #{@line})" # rubocop:disable Layout/LineLength
end