Class: OldeCodeFinder::Finder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, pctg) ⇒ Finder

Returns a new instance of Finder.



8
9
10
11
# File 'lib/olde_code_finder/finder.rb', line 8

def initialize(file, pctg)
  @file = file
  @pctg = pctg
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

#pctgObject

Returns the value of attribute pctg.



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

def pctg
  @pctg
end

Instance Method Details

#check_by_author(author) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/olde_code_finder/finder.rb', line 13

def check_by_author(author)
  return if binary?
  total_lines = git_blame_output.size
  author_lines = git_blame_output.grep(/#{author}/).size
  actual_percent = calculate_percent(author_lines, total_lines)
  if actual_percent > pctg.to_f
    puts "More than #{pctg}% of #{file} was written by #{author} (#{actual_percent}%)"
  end
end

#check_by_date(date_string) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/olde_code_finder/finder.rb', line 23

def check_by_date(date_string)
  return if binary?
  years_ago = date_string.match(/^(\d+)/)[1].to_i
  date_threshold = (Date.today - (years_ago*365))
  total_lines = git_blame_output.size
  older_lines = git_blame_output.select {|line| Date.strptime(line.match(/.*(\d{4}-\d{2}-\d{2})/)[1]) < date_threshold }.size
  actual_percent = calculate_percent(older_lines, total_lines)
  if actual_percent > pctg.to_f
    puts "More than #{pctg}% of #{file} was written more than #{years_ago} years ago (#{actual_percent}%)"
  end
end