Class: Apoptosis::Apoptosis
- Inherits:
-
Object
- Object
- Apoptosis::Apoptosis
- Defined in:
- lib/apoptosis/apoptosis.rb
Instance Attribute Summary collapse
-
#basedir ⇒ Object
Returns the value of attribute basedir.
-
#contents ⇒ Object
Returns the value of attribute contents.
Instance Method Summary collapse
- #extract_date(line) ⇒ Object
- #get_blame(file) ⇒ Object
-
#initialize ⇒ Apoptosis
constructor
A new instance of Apoptosis.
-
#old?(line) ⇒ Boolean
Old is defined as a year for now, just for fun Should probably make it command line configurable.
- #process_blame(blame) ⇒ Object
- #process_contents ⇒ Object
Constructor Details
permalink #initialize ⇒ Apoptosis
Returns a new instance of Apoptosis.
5 6 7 8 |
# File 'lib/apoptosis/apoptosis.rb', line 5 def initialize @basedir = Dir.pwd @contents = Dir['**/*.*'] end |
Instance Attribute Details
permalink #basedir ⇒ Object
Returns the value of attribute basedir.
3 4 5 |
# File 'lib/apoptosis/apoptosis.rb', line 3 def basedir @basedir end |
permalink #contents ⇒ Object
Returns the value of attribute contents.
3 4 5 |
# File 'lib/apoptosis/apoptosis.rb', line 3 def contents @contents end |
Instance Method Details
permalink #extract_date(line) ⇒ Object
[View source]
51 52 53 |
# File 'lib/apoptosis/apoptosis.rb', line 51 def extract_date(line) line.scan(/[0-9]{4}-[0-9]{2}-[0-9]{2}/)[0] end |
permalink #get_blame(file) ⇒ Object
[View source]
10 11 12 |
# File 'lib/apoptosis/apoptosis.rb', line 10 def get_blame(file) `git blame #{@basedir+'/'+file}` end |
permalink #old?(line) ⇒ Boolean
Old is defined as a year for now, just for fun Should probably make it command line configurable
28 29 30 31 |
# File 'lib/apoptosis/apoptosis.rb', line 28 def old?(line) today = Date.today() return (today.year > line.year) && (today.month >= line.month) end |
permalink #process_blame(blame) ⇒ Object
[View source]
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apoptosis/apoptosis.rb', line 14 def process_blame(blame) offenders = [] blame.each_line do |l| line_date = Date.parse(extract_date(l)) if line_date && old?(line_date) offenders << l end end offenders end |
permalink #process_contents ⇒ Object
[View source]
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/apoptosis/apoptosis.rb', line 33 def process_contents outfile = File.open("DeathRow.md", "w+") @contents.each do |f| begin lines = process_blame(get_blame(f)) if lines.length > 0 outfile.puts(@basedir+'/'+f) outfile.puts("=====") lines.each do |l| outfile.puts(l) end end rescue end end outfile.close end |