Class: Todidnt::TodoLine

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

Constant Summary collapse

IGNORE =
%r{assets/js|third_?party|node_modules|jquery|Binary}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, line_number, content) ⇒ TodoLine

Returns a new instance of TodoLine.



20
21
22
23
24
# File 'lib/todidnt/todo_line.rb', line 20

def initialize(filename, line_number, content)
  @filename = filename
  @line_number = line_number
  @content = content
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



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

def author
  @author
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#filenameObject (readonly)

Returns the value of attribute filename.



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

def filename
  @filename
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



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

def line_number
  @line_number
end

Class Method Details

.all(expressions) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/todidnt/todo_line.rb', line 7

def self.all(expressions)
  options = [['-n']]
  expressions.each { |e| options << ['-e', e] }

  grep = GitCommand.new(:grep, options)
  grep.output_lines.map do |line|
    filename, line_number, content = line.split(/:/, 3)
    unless filename =~ IGNORE
      lines = self.new(filename, line_number.to_i, content.strip[0..100])
    end
  end.compact
end

Instance Method Details

#populate_blameObject

TODO: This logic should probably be moved out somewhere else



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/todidnt/todo_line.rb', line 27

def populate_blame
  options = [
    ['--line-porcelain'],
    ['-L', "#{@line_number},#{@line_number}"],
    [@filename]
  ]

  blame = GitCommand.new(:blame, options)
  blame.output_lines.each do |line|
    if (author = /author (.*)/.match(line))
      @author = author[1]
    elsif (author_time = /author-time (.*)/.match(line))
      @timestamp = author_time[1].to_i
    end
  end
end

#prettyObject



48
49
50
# File 'lib/todidnt/todo_line.rb', line 48

def pretty
  "#{pretty_time} (#{author}, #{filename}:#{line_number}): #{content}"
end

#pretty_timeObject



44
45
46
# File 'lib/todidnt/todo_line.rb', line 44

def pretty_time
  Time.at(@timestamp).strftime('%F')
end