Class: Cease::Eviction::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/cease/eviction/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chunk:, comments:, statement:) ⇒ Context

Returns a new instance of Context.



58
59
60
61
62
# File 'lib/cease/eviction/context.rb', line 58

def initialize(chunk:, comments:, statement:)
  @chunk = chunk 
  @comments = comments
  @statement = statement
end

Instance Attribute Details

#chunkObject (readonly)

Returns the value of attribute chunk.



90
91
92
# File 'lib/cease/eviction/context.rb', line 90

def chunk
  @chunk
end

#commentsObject (readonly)

Returns the value of attribute comments.



90
91
92
# File 'lib/cease/eviction/context.rb', line 90

def comments
  @comments
end

#statementObject (readonly)

Returns the value of attribute statement.



90
91
92
# File 'lib/cease/eviction/context.rb', line 90

def statement
  @statement
end

Class Method Details

.from_source(source:) ⇒ Array<Cease::Eviction>

Returns:



15
16
17
18
19
# File 'lib/cease/eviction/context.rb', line 15

def from_source(source:)
  source_to_chunks(source) do |chunk, statement, comments|
    new(comments: comments, statement: statement, chunk: chunk)
  end.compact
end

Instance Method Details

#descriptionObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cease/eviction/context.rb', line 64

def description
  indent = ' ' * 2
  lines_output = lines.inspect
  alignment = ' ' * (lines_output.length - indent.length)
  result = '' 

  header = "#{indent}#{Rainbow(lines_output).blue}: "\
    "#{Rainbow(statement.open_comment.past_due_description).indianred}\n"

  scope.format.each do |line|
    result << "#{alignment}#{line}\n"
  end

  "#{header}#{Rainbow(result).wheat}\n"
end

#linesObject



80
81
82
83
# File 'lib/cease/eviction/context.rb', line 80

def lines
  return [] unless statement.valid?
  statement.lines
end

#overdue?Boolean

Returns:

  • (Boolean)


85
86
87
88
# File 'lib/cease/eviction/context.rb', line 85

def overdue?
  return false unless statement.valid?
  statement.open_comment.overdue?
end