Class: Repository

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dir, translations) ⇒ Repository

Returns a new instance of Repository.



8
9
10
11
12
13
# File 'lib/repository.rb', line 8

def initialize(name, dir, translations)
  @name = name
  @dir = dir
  @delimiter = "#{200.chr}@@@"
  @translations = translations
end

Instance Attribute Details

#commitersObject (readonly)

Returns the value of attribute commiters.



6
7
8
# File 'lib/repository.rb', line 6

def commiters
  @commiters
end

#dirObject

Returns the value of attribute dir.



5
6
7
# File 'lib/repository.rb', line 5

def dir
  @dir
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/repository.rb', line 5

def name
  @name
end

#summaryObject (readonly)

Returns the value of attribute summary.



6
7
8
# File 'lib/repository.rb', line 6

def summary
  @summary
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/repository.rb', line 5

def url
  @url
end

Instance Method Details

#calculate_stats(from = Date.new, to = Date.new) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/repository.rb', line 52

def calculate_stats(from = Date.new, to = Date.new)
  regexp = Regexp.new('\A((\w+\s?)+)\s*((([\d-]+\s+[\d-]+.*)*\s)*)')
  log = self.extract_log(from, to)
  log[0] = '' unless log == ""

  match = regexp.match(log)
  @commiters = Hash.new
  while !match.nil?
    email = match[1].gsub("\n", "")
    if (@translations[email])
      email = @translations[email]
    end

    if @commiters[email].nil?
      @commiters[email] = 0
    end

    commit_informations = match[3]
    commit_informations.split("\n")
    for commit_information in commit_informations
      item = commit_information.split(/\s+/)
      @commiters[email] += item[0].to_i + item[1].to_i
    end
    log.gsub!(regexp,"")
    match = regexp.match(log)
  end
end

#cloneObject



15
16
17
# File 'lib/repository.rb', line 15

def clone
  `cd #{dir} && git clone #{url} > /dev/null 2>&1`
end

#extract_log(from = Date.new, to = Date.new) ⇒ Object



23
24
25
26
27
28
# File 'lib/repository.rb', line 23

def extract_log(from = Date.new, to = Date.new)
  start_date = "#{Date.new - from} days ago"
  end_date = "#{Date.new - to} days ago"
  log = `cd #{dir} && git log --since="#{start_date}" --until="#{end_date} days ago" --pretty=tformat:"%n%an" --numstat --ignore-space-change`
  return log
end

#extract_log_with_messages(from = Date.new, to = Date.new) ⇒ Object



30
31
32
33
34
35
# File 'lib/repository.rb', line 30

def extract_log_with_messages(from = Date.new, to = Date.new)
  start_date = "#{Date.new - from} days ago"
  end_date = "#{Date.new - to} days ago"
  log = `cd #{dir} && git log --since="#{start_date}" --until="#{end_date} days ago" --pretty=tformat:"%an%n%at%n%s#{@delimiter}"`
  return log
end

#generate_summary(from = Date.new, to = Date.new) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/repository.rb', line 37

def generate_summary(from = Date.new, to = Date.new)
  log = self.extract_log_with_messages(from, to)
  @summary = Hash.new
  for commit in log.split(@delimiter)
    temp = []
    for info in commit.split("\n")
      temp.push info unless info == ""
    end
    if (@translations[temp[0]])
      temp[0] = @translations[temp[0]]
    end
    @summary[temp[1]] = {:commiter => temp[0], :time => Time.at(temp[1].to_i), :message => temp[2]} if temp[1]
  end
end

#pullObject



19
20
21
# File 'lib/repository.rb', line 19

def pull
  `cd #{dir} && git pull`
end