Class: Twigg::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/twigg/commit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Commit

Returns a new instance of Commit.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
# File 'lib/twigg/commit.rb', line 5

def initialize(options)
  raise ArgumentError unless @repo    = options[:repo]
  raise ArgumentError unless @commit  = options[:commit]
  raise ArgumentError unless @subject = options[:subject]
  raise ArgumentError unless @body    = options[:body]
  raise ArgumentError unless @author  = options[:author]
  raise ArgumentError unless @date    = options[:date]
  raise ArgumentError unless @stat    = options[:stat]
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def body
  @body
end

#commitObject (readonly)

Returns the value of attribute commit.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def commit
  @commit
end

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def date
  @date
end

#repoObject (readonly)

Returns the value of attribute repo.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def repo
  @repo
end

#statObject (readonly)

Returns the value of attribute stat.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def stat
  @stat
end

#subjectObject (readonly)

Returns the value of attribute subject.



3
4
5
# File 'lib/twigg/commit.rb', line 3

def subject
  @subject
end

Instance Method Details

#author_namesObject



21
22
23
# File 'lib/twigg/commit.rb', line 21

def author_names
  @author.split(/\+|&|,|\band\b/).map(&:strip)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/twigg/commit.rb', line 25

def eql?(other)
  other.is_a?(Commit)         &&
    other.repo    == @repo    &&
    other.commit  == @commit  &&
    other.subject == @subject &&
    other.body    == @body    &&
    other.author  == @author  &&
    other.date    == @date    &&
    other.stat    == @stat
end

#filtered_commit_messageObject



36
37
38
39
40
# File 'lib/twigg/commit.rb', line 36

def filtered_commit_message
  @filtered_commit_message ||= @body.reject do |line|
    line =~ /^[a-z-]+: /i # filter out Change-Id:, Signed-off-by: etc
  end.concat([@subject]).join("\n").chomp
end

#flesch_reading_easeObject



42
43
44
# File 'lib/twigg/commit.rb', line 42

def flesch_reading_ease
  @flesch_reading_ease ||= Flesch.new(filtered_commit_message).reading_ease
end

#inspectObject



51
52
53
54
55
56
57
# File 'lib/twigg/commit.rb', line 51

def inspect
  "repo: #{@repo.name}\n" +
    "commit: #{@commit}\n" +
    "subject: #{@subject}\n" +
    "author: #{@author}\n" +
    "stat: +#{@stat[:additions]}, -#{@stat[:deletions]}"
end


15
16
17
18
19
# File 'lib/twigg/commit.rb', line 15

def link
  if Config.github.organization
    "https://github.com/#{Config.github.organization}/#{repo.name}/commit/#{commit}"
  end
end

#russiannessObject

Return the length of the commit message in lines.



47
48
49
# File 'lib/twigg/commit.rb', line 47

def russianness
  filtered_commit_message.lines.count
end