Class: Black::Diff::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/black/diff.rb

Overview

Nicer line API for views

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ Line

Returns a new instance of Line.



108
109
110
# File 'lib/black/diff.rb', line 108

def initialize(line)
  @line = line
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/black/diff.rb', line 112

def changed?
  ['addition', 'deletion'].include? @line['type']
end

#contentObject



120
121
122
# File 'lib/black/diff.rb', line 120

def content
  @content ||= @line['content'].slice(/^.{1}/, @line['content'].length)
end

#deletion?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/black/diff.rb', line 116

def deletion?
  type == 'deletion'
end

#new_line_numberObject



128
129
130
# File 'lib/black/diff.rb', line 128

def new_line_number
  type == 'deletion' ? nil : @line['new_line_number']
end

#old_line_numberObject



132
133
134
# File 'lib/black/diff.rb', line 132

def old_line_number
  type == 'addition' ? nil : @line['old_line_number']
end

#typeObject



124
125
126
# File 'lib/black/diff.rb', line 124

def type
  @line['type']
end