Class: ClosingComments::Source

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/closing_comments/source.rb

Defined Under Namespace

Classes: Problem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, content:) ⇒ Source

Returns a new instance of Source.



15
16
17
18
# File 'lib/closing_comments/source.rb', line 15

def initialize(path:, content:)
  @path = path
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/closing_comments/source.rb', line 8

def content
  @content
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/closing_comments/source.rb', line 8

def path
  @path
end

Class Method Details

.from(path:) ⇒ Object



11
12
13
# File 'lib/closing_comments/source.rb', line 11

def self.from(path:)
  new(path: path, content: File.read(path))
end

Instance Method Details

#fixObject



32
33
34
# File 'lib/closing_comments/source.rb', line 32

def fix
  lines.map.with_index(1) { |default, no| fixes[no] || default }.join("\n")
end

#problematic?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/closing_comments/source.rb', line 20

def problematic?
  problems.count.positive?
end

#problemsObject



24
25
26
27
28
29
30
# File 'lib/closing_comments/source.rb', line 24

def problems
  @problems ||=
    entities
    .reject(&:single_line?)
    .reject(&method(:commented?))
    .map { |ent| Problem.new(ent, line(number: ent.last_line)) }
end