Class: Kachikachi::PatchBody
- Inherits:
-
Object
- Object
- Kachikachi::PatchBody
- Defined in:
- lib/kachikachi/patch_body.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #ignore_added_lines ⇒ Object
- #ignore_comment_lines(pattern) ⇒ Object
- #ignore_unmodified_lines ⇒ Object
- #ignore_white_space ⇒ Object
-
#initialize(content, options) ⇒ PatchBody
constructor
A new instance of PatchBody.
- #only_removed ⇒ Object
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, ) @content = content || '' @options = end |
Instance Attribute Details
#content ⇒ Object
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_lines ⇒ Object
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_lines ⇒ Object
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_space ⇒ Object
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_removed ⇒ Object
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 |