Class: I18n::Tasks::Scanners::Results::Occurrence
- Inherits:
-
Object
- Object
- I18n::Tasks::Scanners::Results::Occurrence
- Defined in:
- lib/i18n/tasks/scanners/results/occurrence.rb
Overview
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
-
#default_arg ⇒ String?
readonly
The value of the ‘default:` argument of the translate call.
-
#line ⇒ String
readonly
The line of the occurrence, excluding the last LF or CRLF.
-
#line_num ⇒ Integer
readonly
Line number of the occurrence, counting from 1.
-
#line_pos ⇒ Integer
readonly
Position of the start of the occurrence in the line, counting from 1.
-
#path ⇒ String
readonly
Source path relative to the current working directory.
-
#pos ⇒ Integer
readonly
Count of characters in the file before the occurrence.
-
#raw_key ⇒ String?
The raw key (for relative keys and references).
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(path:, pos:, line_num:, line_pos:, line:, raw_key: nil, default_arg: nil) ⇒ Occurrence
constructor
rubocop:disable Metrics/ParameterLists.
-
#inspect ⇒ Object
rubocop:enable Metrics/ParameterLists.
Constructor Details
#initialize(path:, pos:, line_num:, line_pos:, line:, raw_key: nil, default_arg: nil) ⇒ Occurrence
rubocop:disable Metrics/ParameterLists
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_arg ⇒ String? (readonly)
Returns 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 |
#line ⇒ String (readonly)
Returns 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_num ⇒ Integer (readonly)
Returns 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_pos ⇒ Integer (readonly)
Returns 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 |
#path ⇒ String (readonly)
Returns 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 |
#pos ⇒ Integer (readonly)
Returns 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_key ⇒ String?
Returns 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
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
59 60 61 |
# File 'lib/i18n/tasks/scanners/results/occurrence.rb', line 59 def eql?(other) self == other end |
#hash ⇒ Object
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 |
#inspect ⇒ Object
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 |