Class: Ginbeer
- Inherits:
-
Object
- Object
- Ginbeer
- Defined in:
- lib/ginbeer/ginbeer.rb,
lib/ginbeer/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #authors ⇒ Object
- #cd_command ⇒ Object
-
#initialize(dir, from = "", to = Time.now) ⇒ Ginbeer
constructor
A new instance of Ginbeer.
- #log_command(author) ⇒ Object
- #shortlog_command ⇒ Object
Constructor Details
#initialize(dir, from = "", to = Time.now) ⇒ Ginbeer
Returns a new instance of Ginbeer.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ginbeer/ginbeer.rb', line 5 def initialize(dir, from="", to=Time.now) @dir = dir @from = from @from_d = nil if @from != "" @from_d = Time.parse(@from) end @to = to # error handling epath = File.(dir) if File.exist?(File.join(epath, '.git')) elsif File.exist?(epath) && (epath =~ /\.git$/) elsif File.exist?(epath) raise InvalidGitRepositoryError.new(epath) else raise NoSuchPathError.new(epath) end end |
Instance Method Details
#authors ⇒ Object
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 52 53 54 55 56 57 58 |
# File 'lib/ginbeer/ginbeer.rb', line 26 def = [] commits = `#{self.shortlog_command}` commits.each_line do |line| line.chomp! /\s*(\d+)\s(.+)/ =~ line count = $1.to_i name = $2 .push(Author.new(name, count)) end .each do || logs = `#{self.log_command()}` logs.each_line do |line| line.chomp! if /file/ =~ line /.*(\d+) insertion.*, (\d+) deletion/ =~ line insertion = $1.to_i deletion = $2.to_i .insertion += insertion .deletion += deletion elsif /\[(.+)\]/ =~ line data = $1 data = Time.parse(data) break if @from_d != nil && data < @from_d # 終了 end end end return end |
#cd_command ⇒ Object
60 61 62 |
# File 'lib/ginbeer/ginbeer.rb', line 60 def cd_command return "cd #{@dir} &&" end |
#log_command(author) ⇒ Object
70 71 72 73 |
# File 'lib/ginbeer/ginbeer.rb', line 70 def log_command() command = "#{self.cd_command} git log --pretty=format:'[%ad]' --shortstat --author='#{.name}' --date=short --before=#{@to}" return command end |
#shortlog_command ⇒ Object
64 65 66 67 68 |
# File 'lib/ginbeer/ginbeer.rb', line 64 def shortlog_command command = "#{self.cd_command} git shortlog -s --no-merges -n --before=#{@to}" command += " --after=#{@from}" if @from != "" return command end |