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|vendor}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, line_number, raw_content) ⇒ TodoLine

Returns a new instance of TodoLine.



25
26
27
28
29
# File 'lib/todidnt/todo_line.rb', line 25

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

Instance Attribute Details

#authorObject

Returns the value of attribute author.



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

def author
  @author
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

#raw_contentObject (readonly)

Returns the value of attribute raw_content.



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

def raw_content
  @raw_content
end

#timestampObject

Returns the value of attribute timestamp.



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

def timestamp
  @timestamp
end

Class Method Details

.all(expressions) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/todidnt/todo_line.rb', line 8

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

  lines = []

  command = GitCommand.new(:grep, options)
  command.execute! do |line|
    filename, line_number, content = line.split(/:/, 3)
    unless filename =~ IGNORE
      lines << self.new(filename, line_number.to_i, content)
    end
  end

  lines
end

Instance Method Details

#contentObject



35
36
37
# File 'lib/todidnt/todo_line.rb', line 35

def content
  raw_content.strip[0..100]
end

#pretty_timeObject



31
32
33
# File 'lib/todidnt/todo_line.rb', line 31

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

#to_hashObject



39
40
41
42
43
44
45
46
47
# File 'lib/todidnt/todo_line.rb', line 39

def to_hash
  {
    :time => pretty_time,
    :author => author,
    :filename => filename,
    :line_number => line_number,
    :content => content
  }
end