Class: Hunkify::Hunk

Inherits:
Struct
  • Object
show all
Defined in:
lib/hunkify/hunk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_headerObject

Returns the value of attribute file_header

Returns:

  • (Object)

    the current value of file_header



4
5
6
# File 'lib/hunkify/hunk.rb', line 4

def file_header
  @file_header
end

#file_pathObject

Returns the value of attribute file_path

Returns:

  • (Object)

    the current value of file_path



4
5
6
# File 'lib/hunkify/hunk.rb', line 4

def file_path
  @file_path
end

#hunk_headerObject

Returns the value of attribute hunk_header

Returns:

  • (Object)

    the current value of hunk_header



4
5
6
# File 'lib/hunkify/hunk.rb', line 4

def hunk_header
  @hunk_header
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



4
5
6
# File 'lib/hunkify/hunk.rb', line 4

def id
  @id
end

#linesObject

Returns the value of attribute lines

Returns:

  • (Object)

    the current value of lines



4
5
6
# File 'lib/hunkify/hunk.rb', line 4

def lines
  @lines
end

Instance Method Details

#to_patchObject



5
6
7
8
9
# File 'lib/hunkify/hunk.rb', line 5

def to_patch
  body = lines.join("\n")
  body += "\n" unless body.end_with?("\n")
  "#{file_header}\n#{hunk_header}\n#{body}"
end

#to_summaryObject



11
12
13
14
15
16
# File 'lib/hunkify/hunk.rb', line 11

def to_summary
  added = lines.count { |l| l.start_with?("+") }
  removed = lines.count { |l| l.start_with?("-") }
  preview = lines.first(6).join("\n")
  "[HUNK #{id}] #{file_path} #{hunk_header}\n#{preview}\n(+#{added} / -#{removed} lines)"
end