Class: Cease::Eviction::Statement

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(open_comment:, close_comment:, source:) ⇒ Statement

Returns a new instance of Statement.

Parameters:

  • open_comment (Parser::Source::Comment)
  • close_comment (Parser::Source::Comment)


19
20
21
22
# File 'lib/cease/eviction/statement.rb', line 19

def initialize(open_comment:, close_comment:, source:)
  @open_comment = Comment.new(comment: open_comment, source: source)
  @close_comment = Comment.new(comment: close_comment, source: source)
end

Instance Attribute Details

#close_commentObject (readonly)

Returns the value of attribute close_comment.



36
37
38
# File 'lib/cease/eviction/statement.rb', line 36

def close_comment
  @close_comment
end

#open_commentObject (readonly)

Returns the value of attribute open_comment.



36
37
38
# File 'lib/cease/eviction/statement.rb', line 36

def open_comment
  @open_comment
end

Class Method Details

.from_comments(*comments) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/cease/eviction/statement.rb', line 6

def self.from_comments(*comments)
  open_comment, close_comment, source = comments

  new(
    open_comment: open_comment,
    close_comment: close_comment,
    source: source
  )
end

Instance Method Details

#linesObject



24
25
26
27
28
29
30
# File 'lib/cease/eviction/statement.rb', line 24

def lines
  return [] unless valid?

  [open_comment, close_comment].map do |eviction_comment|
    eviction_comment.loc&.line
  end
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cease/eviction/statement.rb', line 32

def valid?
  [open_comment, close_comment].all?(&:valid?)
end