Class: GemfileSorter::Line::Group

Inherits:
BlockOfGems show all
Defined in:
lib/gemfile_sorter/line/group.rb

Instance Attribute Summary collapse

Attributes inherited from BlockOfGems

#gems, #line, #line_number

Instance Method Summary collapse

Methods inherited from BlockOfGems

#add, #empty?, #gem_string, #leading_spaces, #to_s

Constructor Details

#initialize(*names, line:, line_number:) ⇒ Group

Returns a new instance of Group.



6
7
8
9
10
# File 'lib/gemfile_sorter/line/group.rb', line 6

def initialize(*names, line:, line_number:)
  @names = names
  @sources = Sources.new
  super(normalized_name, line:, line_number:)
end

Instance Attribute Details

#namesObject

Returns the value of attribute names.



4
5
6
# File 'lib/gemfile_sorter/line/group.rb', line 4

def names
  @names
end

#sourcesObject

Returns the value of attribute sources.



4
5
6
# File 'lib/gemfile_sorter/line/group.rb', line 4

def sources
  @sources
end

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
# File 'lib/gemfile_sorter/line/group.rb', line 20

def <=>(other)
  normalized_name <=> other.normalized_name
rescue
  raise InvalidLineComparisonError
end

#container?Boolean

Returns:

  • (Boolean)


12
# File 'lib/gemfile_sorter/line/group.rb', line 12

def container? = true

#inside_block_mapObject



14
# File 'lib/gemfile_sorter/line/group.rb', line 14

def inside_block_map = sources

#normalized_nameObject



16
17
18
# File 'lib/gemfile_sorter/line/group.rb', line 16

def normalized_name
  Array(names).flatten.map { _1.delete_prefix(":") }.sort.join(", ")
end