Class: Debtective::Todos::Todo

Inherits:
Object
  • Object
show all
Defined in:
lib/debtective/todos/todo.rb

Overview

Hold todo information

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathname, lines, todo_boundaries, statement_boundaries) ⇒ Todo

Returns a new instance of Todo.

Parameters:

  • pathname (Pathname)
  • lines (Array<String>)
  • todo_boundaries (Range)
  • statement_boundaries (Range)


22
23
24
25
26
27
# File 'lib/debtective/todos/todo.rb', line 22

def initialize(pathname, lines, todo_boundaries, statement_boundaries)
  @pathname = pathname
  @lines = lines
  @todo_boundaries = todo_boundaries
  @statement_boundaries = statement_boundaries
end

Instance Attribute Details

#pathnameObject

Returns the value of attribute pathname.



16
17
18
# File 'lib/debtective/todos/todo.rb', line 16

def pathname
  @pathname
end

#statement_boundariesObject

Returns the value of attribute statement_boundaries.



16
17
18
# File 'lib/debtective/todos/todo.rb', line 16

def statement_boundaries
  @statement_boundaries
end

#todo_boundariesObject

Returns the value of attribute todo_boundaries.



16
17
18
# File 'lib/debtective/todos/todo.rb', line 16

def todo_boundaries
  @todo_boundaries
end

Class Method Details

.build(pathname, index) ⇒ Debtective::Todos::Todo



11
12
13
# File 'lib/debtective/todos/todo.rb', line 11

def build(pathname, index)
  Build.new(pathname, index).call
end

Instance Method Details

#commitGit::Object::Commit

return commit that introduced the todo

Returns:

  • (Git::Object::Commit)


43
44
45
# File 'lib/debtective/todos/todo.rb', line 43

def commit
  @commit ||= Debtective::FindCommit.new(@pathname, @lines[@todo_boundaries.min]).call
end

#daysInteger

Returns:

  • (Integer)


48
49
50
51
52
# File 'lib/debtective/todos/todo.rb', line 48

def days
  return if commit.time.nil?

  ((Time.now - commit.time) / (24 * 60 * 60)).round
end

#locationString

location in the codebase

Returns:

  • (String)


31
32
33
# File 'lib/debtective/todos/todo.rb', line 31

def location
  "#{@pathname}:#{@todo_boundaries.min + 1}"
end

#sizeInteger

size of the todo code

Returns:

  • (Integer)


37
38
39
# File 'lib/debtective/todos/todo.rb', line 37

def size
  @statement_boundaries.size
end

#to_hHash

Returns:

  • (Hash)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/debtective/todos/todo.rb', line 55

def to_h
  {
    pathname: pathname,
    location: location,
    todo_boundaries: todo_boundaries.minmax,
    statement_boundaries: statement_boundaries.minmax,
    size: size,
    commit: {
      sha: commit.sha,
      author: commit.author.to_h,
      time: commit.time
    }
  }
end