Class: GitEvolution::Commit
- Inherits:
-
Object
- Object
- GitEvolution::Commit
- Defined in:
- lib/git_evolution/commit.rb
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#deletions ⇒ Object
readonly
Returns the value of attribute deletions.
-
#raw_commit ⇒ Object
readonly
Returns the value of attribute raw_commit.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(raw_commit) ⇒ Commit
constructor
A new instance of Commit.
- #parse_body_data! ⇒ Object
- #parse_diff_data! ⇒ Object
- #parse_meta_data! ⇒ Object
Constructor Details
#initialize(raw_commit) ⇒ Commit
Returns a new instance of Commit.
5 6 7 8 9 10 11 |
# File 'lib/git_evolution/commit.rb', line 5 def initialize(raw_commit) @raw_commit = raw_commit parse_body_data! parse_diff_data! end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def additions @additions end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def body @body end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def date @date end |
#deletions ⇒ Object (readonly)
Returns the value of attribute deletions.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def deletions @deletions end |
#raw_commit ⇒ Object (readonly)
Returns the value of attribute raw_commit.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def raw_commit @raw_commit end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def sha @sha end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/git_evolution/commit.rb', line 3 def subject @subject end |
Instance Method Details
#parse_body_data! ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/git_evolution/commit.rb', line 19 def parse_body_data! raw_body_lines = (raw_commit + "\n\u0000").scan(/^Date:.*?$(.*?)^[diff|\u0000]/m).flatten.first.strip.split("\n") @subject = raw_body_lines.first.strip if raw_body_lines.size > 1 @body = raw_body_lines[1..-1].map { |line| line.gsub(/^\s+/, '') }.join("\n") @body.sub!(/\n+/, '') if @body.start_with?("\n") end end |
#parse_diff_data! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/git_evolution/commit.rb', line 29 def parse_diff_data! raw_diff_lines = raw_commit.scan(/^@@.*?$(.*)?/m).flatten.first if raw_diff_lines raw_diff_lines = raw_diff_lines.strip.split("\n") @additions = raw_diff_lines.count { |line| line.start_with?('+') } @deletions = raw_diff_lines.count { |line| line.start_with?('-') } else @additions = 0 @deletions = 0 end end |
#parse_meta_data! ⇒ Object
13 14 15 16 17 |
# File 'lib/git_evolution/commit.rb', line 13 def @sha = raw_commit.scan(/^commit\s+(.*?)$/).flatten.first.strip = raw_commit.scan(/^Author:\s+(.*?)$/).flatten.first.strip @date= raw_commit.scan(/^Date:\s+(.*?)$/).flatten.first.strip end |