Class: Activigit::Repository
- Inherits:
-
Object
- Object
- Activigit::Repository
- Defined in:
- lib/activigit.rb
Instance Method Summary collapse
- #group_by_days ⇒ Object
- #group_by_months ⇒ Object
- #group_with_format(format) ⇒ Object
-
#initialize(path) ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize(path) ⇒ Repository
Returns a new instance of Repository.
9 10 11 |
# File 'lib/activigit.rb', line 9 def initialize(path) @path = path end |
Instance Method Details
#group_by_days ⇒ Object
13 14 15 |
# File 'lib/activigit.rb', line 13 def group_by_days group_with_format '%Y-%m-%d' end |
#group_by_months ⇒ Object
17 18 19 |
# File 'lib/activigit.rb', line 17 def group_by_months group_with_format '%Y-%m' end |
#group_with_format(format) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/activigit.rb', line 21 def group_with_format(format) logs = '' Dir.chdir(@path) do logs = `git log --branches --format=%cI`.split("\n") end logs_grouped = logs.group_by { |log| Date.parse(log).strftime(format) } last_commit_date = Date.parse logs.first current_date = Date.parse logs.last counts = {} while current_date != last_commit_date current_date_str = current_date.strftime(format) counts[current_date_str] = if logs_grouped[current_date_str].nil? 0 else logs_grouped[current_date_str].count end current_date += 1 end g = Gruff::Line.new g.title = name(format) # transform `['a', 'b', 'c']` into `{0=>'a', 1=>'b', 2=>'c'}` g.labels = counts.map.with_index { |k, i| [i, k.first] }.to_h g.data :commits, counts.values g.write filename(format) end |