Class: RapidDiffs::Viewers::Text::LineNumberComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/rapid_diffs/viewers/text/line_number_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(line:, line_id:, position:) ⇒ LineNumberComponent

Returns a new instance of LineNumberComponent.



7
8
9
10
11
# File 'app/components/rapid_diffs/viewers/text/line_number_component.rb', line 7

def initialize(line:, line_id:, position:)
  @line = line
  @line_id = line_id
  @position = position
end

Instance Method Details

#change_typeObject



17
18
19
20
21
22
23
# File 'app/components/rapid_diffs/viewers/text/line_number_component.rb', line 17

def change_type
  return unless @line
  return 'meta' if @line.meta?
  return 'added' if @line.added?

  'removed' if @line.removed?
end

#labelObject



25
26
27
28
29
30
# File 'app/components/rapid_diffs/viewers/text/line_number_component.rb', line 25

def label
  return s_('RapidDiffs|Removed line %d') % line_number if @line.removed?
  return s_('RapidDiffs|Added line %d') % line_number if @line.added?

  s_('RapidDiffs|Line %d') % line_number
end

#line_numberObject



13
14
15
# File 'app/components/rapid_diffs/viewers/text/line_number_component.rb', line 13

def line_number
  @position == :old ? @line.old_pos : @line.new_pos
end

#visible?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
# File 'app/components/rapid_diffs/viewers/text/line_number_component.rb', line 32

def visible?
  return false unless @line && !@line.meta?

  case @position
  when :old then !@line.added?
  when :new then !@line.removed?
  else false
  end
end