Class: Kachikachi::PatchBody

Inherits:
Object
  • Object
show all
Defined in:
lib/kachikachi/patch_body.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, options) ⇒ PatchBody

Returns a new instance of PatchBody.



5
6
7
8
# File 'lib/kachikachi/patch_body.rb', line 5

def initialize(content, options)
  @content = content || ''
  @options = options
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/kachikachi/patch_body.rb', line 3

def content
  @content
end

Instance Method Details

#ignore_added_linesObject



24
25
26
# File 'lib/kachikachi/patch_body.rb', line 24

def ignore_added_lines
  PatchBody.new(@content.gsub(/^\+.*(\n|\r\n|\r)/, ''), @options)
end

#ignore_comment_lines(pattern) ⇒ Object



32
33
34
35
# File 'lib/kachikachi/patch_body.rb', line 32

def ignore_comment_lines(pattern)
  comment_line_regexp = Regexp.new("^[-+]?\s*#{pattern}.*(\n|\r\n|\r)")
  PatchBody.new(@content.gsub(comment_line_regexp, ''), @options)
end

#ignore_unmodified_linesObject



20
21
22
# File 'lib/kachikachi/patch_body.rb', line 20

def ignore_unmodified_lines
  PatchBody.new(@content.gsub(/^\s.*(\n|\r\n|\r)/, ''), @options)
end

#ignore_white_spaceObject



28
29
30
# File 'lib/kachikachi/patch_body.rb', line 28

def ignore_white_space
  PatchBody.new(@content.gsub(/^(-|\+)\s*(\n|\r\n|\r)/, ''), @options)
end

#only_removedObject



10
11
12
13
14
15
16
17
18
# File 'lib/kachikachi/patch_body.rb', line 10

def only_removed
  patch = ignore_unmodified_lines
            .ignore_added_lines
  patch = patch.ignore_white_space if @options['ignore-white-space']
  pattern = @options['ignore-comment-regexp']
  patch = patch.ignore_comment_lines(pattern) if pattern

  patch
end