Class: Gitlab::Graphs::Commits
- Inherits:
-
Object
- Object
- Gitlab::Graphs::Commits
- Defined in:
- lib/gitlab/graphs/commits.rb
Instance Attribute Summary collapse
-
#commits ⇒ Object
readonly
Returns the value of attribute commits.
-
#commits_per_month ⇒ Object
readonly
Returns the value of attribute commits_per_month.
-
#commits_per_time ⇒ Object
readonly
Returns the value of attribute commits_per_time.
-
#commits_per_week_days ⇒ Object
readonly
Returns the value of attribute commits_per_week_days.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Instance Method Summary collapse
- #authors ⇒ Object
- #collect_data ⇒ Object
- #commit_per_day ⇒ Object
-
#initialize(commits) ⇒ Commits
constructor
A new instance of Commits.
Constructor Details
#initialize(commits) ⇒ Commits
Returns a new instance of Commits.
9 10 11 12 13 14 15 16 |
# File 'lib/gitlab/graphs/commits.rb', line 9 def initialize(commits) @commits = commits @start_date = commits.last.committed_date.to_date @end_date = commits.first.committed_date.to_date @duration = (@end_date - @start_date).to_i collect_data end |
Instance Attribute Details
#commits ⇒ Object (readonly)
Returns the value of attribute commits.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def commits @commits end |
#commits_per_month ⇒ Object (readonly)
Returns the value of attribute commits_per_month.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def commits_per_month @commits_per_month end |
#commits_per_time ⇒ Object (readonly)
Returns the value of attribute commits_per_time.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def commits_per_time @commits_per_time end |
#commits_per_week_days ⇒ Object (readonly)
Returns the value of attribute commits_per_week_days.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def commits_per_week_days @commits_per_week_days end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def duration @duration end |
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def end_date @end_date end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
6 7 8 |
# File 'lib/gitlab/graphs/commits.rb', line 6 def start_date @start_date end |
Instance Method Details
#authors ⇒ Object
18 19 20 |
# File 'lib/gitlab/graphs/commits.rb', line 18 def @authors ||= @commits.map(&:author_email).uniq.size end |
#collect_data ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gitlab/graphs/commits.rb', line 26 def collect_data @commits_per_week_days = {} Date::DAYNAMES.each { |day| @commits_per_week_days[day] = 0 } @commits_per_time = {} (0..23).to_a.each { |hour| @commits_per_time[hour] = 0 } @commits_per_month = {} (1..31).to_a.each { |day| @commits_per_month[day] = 0 } @commits.each do |commit| hour = commit.committed_date.strftime('%k').to_i day_of_month = commit.committed_date.strftime('%e').to_i weekday = commit.committed_date.strftime('%A') @commits_per_week_days[weekday] ||= 0 @commits_per_week_days[weekday] += 1 @commits_per_time[hour] ||= 0 @commits_per_time[hour] += 1 @commits_per_month[day_of_month] ||= 0 @commits_per_month[day_of_month] += 1 end end |
#commit_per_day ⇒ Object
22 23 24 |
# File 'lib/gitlab/graphs/commits.rb', line 22 def commit_per_day @commit_per_day ||= (@commits.size.to_f / (@duration + 1)).round(1) end |