Class: GemfileSorter::BlockMap
- Inherits:
-
Object
- Object
- GemfileSorter::BlockMap
- Defined in:
- lib/gemfile_sorter/block_map.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
Returns the value of attribute blocks.
Instance Method Summary collapse
- #add(names, line:, line_number:) ⇒ Object
- #add_gem(gem) ⇒ Object
- #empty? ⇒ Boolean
- #extra_line_unless_empty ⇒ Object
-
#initialize ⇒ BlockMap
constructor
A new instance of BlockMap.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ BlockMap
Returns a new instance of BlockMap.
5 6 7 |
# File 'lib/gemfile_sorter/block_map.rb', line 5 def initialize @blocks = {} end |
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
3 4 5 |
# File 'lib/gemfile_sorter/block_map.rb', line 3 def blocks @blocks end |
Instance Method Details
#add(names, line:, line_number:) ⇒ Object
19 20 21 22 |
# File 'lib/gemfile_sorter/block_map.rb', line 19 def add(names, line:, line_number:) block = block(names, line:, line_number:) blocks[block.normalized_name] ||= block end |
#add_gem(gem) ⇒ Object
15 16 17 |
# File 'lib/gemfile_sorter/block_map.rb', line 15 def add_gem(gem) add(gem.inline_result, line: gem.inline_line, line_number: gem.line_number) end |
#empty? ⇒ Boolean
9 |
# File 'lib/gemfile_sorter/block_map.rb', line 9 def empty? = blocks.empty? |
#extra_line_unless_empty ⇒ Object
11 12 13 |
# File 'lib/gemfile_sorter/block_map.rb', line 11 def extra_line_unless_empty empty? ? "" : "\n" end |
#to_s ⇒ Object
24 25 26 27 |
# File 'lib/gemfile_sorter/block_map.rb', line 24 def to_s extra_line_unless_empty + blocks.values.sort.map { _1.to_s }.join.delete_prefix("\n") end |