Class: I18nContextGenerator::ChangedLocation
- Inherits:
-
Data
- Object
- Data
- I18nContextGenerator::ChangedLocation
- Defined in:
- lib/i18n_context_generator/changed_location.rb
Overview
A line in a Git diff, including the revision side needed by review clients.
fallback_line identifies a corresponding line in the head revision. It is
useful when a removed translator comment needs a right-side suggestion anchor.
Instance Attribute Summary collapse
-
#fallback_line ⇒ Object
readonly
Returns the value of attribute fallback_line.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file:, line:, side: :right, fallback_line: nil) ⇒ ChangedLocation
constructor
A new instance of ChangedLocation.
- #left? ⇒ Boolean
- #review_side ⇒ Object
- #right? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(file:, line:, side: :right, fallback_line: nil) ⇒ ChangedLocation
Returns a new instance of ChangedLocation.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/i18n_context_generator/changed_location.rb', line 9 def initialize(file:, line:, side: :right, fallback_line: nil) normalized_side = side.to_s.downcase.to_sym raise ArgumentError, "Unsupported diff side: #{side}" unless %i[left right].include?(normalized_side) super( file: file.to_s, line: Integer(line), side: normalized_side, fallback_line: fallback_line && Integer(fallback_line) ) end |
Instance Attribute Details
#fallback_line ⇒ Object (readonly)
Returns the value of attribute fallback_line
8 9 10 |
# File 'lib/i18n_context_generator/changed_location.rb', line 8 def fallback_line @fallback_line end |
#file ⇒ Object (readonly)
Returns the value of attribute file
8 9 10 |
# File 'lib/i18n_context_generator/changed_location.rb', line 8 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line
8 9 10 |
# File 'lib/i18n_context_generator/changed_location.rb', line 8 def line @line end |
#side ⇒ Object (readonly)
Returns the value of attribute side
8 9 10 |
# File 'lib/i18n_context_generator/changed_location.rb', line 8 def side @side end |
Class Method Details
.parse(value) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/i18n_context_generator/changed_location.rb', line 21 def self.parse(value) return value if value.is_a?(self) match = /\A(.+):(\d+)\z/.match(value.to_s) raise ArgumentError, "Invalid changed location: #{value.inspect}" unless match new(file: match[1], line: match[2], side: :right) end |
Instance Method Details
#left? ⇒ Boolean
30 31 32 |
# File 'lib/i18n_context_generator/changed_location.rb', line 30 def left? side == :left end |
#review_side ⇒ Object
38 39 40 |
# File 'lib/i18n_context_generator/changed_location.rb', line 38 def review_side side.to_s.upcase end |
#right? ⇒ Boolean
34 35 36 |
# File 'lib/i18n_context_generator/changed_location.rb', line 34 def right? side == :right end |
#to_h ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/i18n_context_generator/changed_location.rb', line 46 def to_h { file: file, line: line, side: side, fallback_line: fallback_line } end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/i18n_context_generator/changed_location.rb', line 42 def to_s "#{file}:#{line}" end |