Class: GemfileSorter::BlockOfGems
- Inherits:
-
Object
- Object
- GemfileSorter::BlockOfGems
show all
- Defined in:
- lib/gemfile_sorter/block_of_gems.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, line:, line_number:) ⇒ BlockOfGems
Returns a new instance of BlockOfGems.
5
6
7
8
9
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 5
def initialize(name, line:, line_number:)
@gems = {}
@line = line
@line_number = line_number
end
|
Instance Attribute Details
#gems ⇒ Object
Returns the value of attribute gems.
3
4
5
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 3
def gems
@gems
end
|
#line ⇒ Object
Returns the value of attribute line.
3
4
5
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 3
def line
@line
end
|
#line_number ⇒ Object
Returns the value of attribute line_number.
3
4
5
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 3
def line_number
@line_number
end
|
Instance Method Details
#add(gem) ⇒ Object
15
16
17
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 15
def add(gem)
@gems[gem.name] = gem
end
|
#container? ⇒ Boolean
11
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 11
def container? = false
|
#empty? ⇒ Boolean
35
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 35
def empty? = gems.empty?
|
#gem_string ⇒ Object
19
20
21
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 19
def gem_string
gems.values.sort.map { _1.to_s }.join.delete_prefix("\n")
end
|
#inside_block_map ⇒ Object
13
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 13
def inside_block_map = nil
|
#leading_spaces ⇒ Object
23
24
25
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 23
def leading_spaces
line.match(/(\A *)/)[1]
end
|
#to_s ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/gemfile_sorter/block_of_gems.rb', line 27
def to_s
"\n" +
line +
gem_string.delete_suffix(",") +
(inside_block_map&.to_s || "") +
"#{leading_spaces}end\n"
end
|