Class: GemfileSorter::CommentGroup

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gemfile_sorter/comment_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*comments) ⇒ CommentGroup

Returns a new instance of CommentGroup.



7
8
9
# File 'lib/gemfile_sorter/comment_group.rb', line 7

def initialize(*comments)
  @comments = comments.flatten
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



5
6
7
# File 'lib/gemfile_sorter/comment_group.rb', line 5

def comments
  @comments
end

Instance Method Details

#<<(comment) ⇒ Object



21
# File 'lib/gemfile_sorter/comment_group.rb', line 21

def <<(comment) = add(comment)

#add(comment) ⇒ Object



17
18
19
# File 'lib/gemfile_sorter/comment_group.rb', line 17

def add(comment)
  self.comments += comment.comments
end

#contentsObject



15
# File 'lib/gemfile_sorter/comment_group.rb', line 15

def contents = comments

#eachObject



25
# File 'lib/gemfile_sorter/comment_group.rb', line 25

def each = comments.each

#empty?Boolean

Returns:

  • (Boolean)


23
# File 'lib/gemfile_sorter/comment_group.rb', line 23

def empty? = comments.empty?

#extra_line_unless_emptyObject



27
28
29
# File 'lib/gemfile_sorter/comment_group.rb', line 27

def extra_line_unless_empty
  empty? ? "" : "\n"
end

#to_sObject



11
12
13
# File 'lib/gemfile_sorter/comment_group.rb', line 11

def to_s
  comments.map { _1.to_s }.join
end