Class: Canopus::BlockMap
- Inherits:
-
Object
- Object
- Canopus::BlockMap
- Defined in:
- lib/canopus/block_map.rb,
sig/display_stages.rbs
Defined Under Namespace
Classes: Block
Instance Attribute Summary collapse
-
#blocks ⇒ Hash[untyped, Block]
readonly
Returns the value of attribute blocks.
Instance Method Summary collapse
- #apply(patch) ⇒ Hash[untyped, Block]
- #at(row) ⇒ Array[Block]
-
#initialize ⇒ BlockMap
constructor
A new instance of BlockMap.
- #insert(id, row:, text:, kind: :diagnostic) ⇒ Block
- #remove(id) ⇒ Block?
Constructor Details
#initialize ⇒ BlockMap
Returns a new instance of BlockMap.
7 |
# File 'lib/canopus/block_map.rb', line 7 def initialize = @blocks = {} |
Instance Attribute Details
#blocks ⇒ Hash[untyped, Block] (readonly)
Returns the value of attribute blocks.
6 7 8 |
# File 'lib/canopus/block_map.rb', line 6 def blocks @blocks end |
Instance Method Details
#apply(patch) ⇒ Hash[untyped, Block]
11 12 13 14 15 16 17 |
# File 'lib/canopus/block_map.rb', line 11 def apply(patch) @blocks.transform_values! do |block| old = patch.before.line_start([block.row, patch.before.line_count - 1].min) row = patch.after.point_at(patch.map_offset(old, bias: :left)).row Block.new(block.id, row, block.text, block.kind) end end |
#at(row) ⇒ Array[Block]
10 |
# File 'lib/canopus/block_map.rb', line 10 def at(row) = @blocks.values.select { |block| block.row == row } |
#insert(id, row:, text:, kind: :diagnostic) ⇒ Block
8 |
# File 'lib/canopus/block_map.rb', line 8 def insert(id, row:, text:, kind: :diagnostic) = @blocks[id] = Block.new(id, row, text, kind) |
#remove(id) ⇒ Block?
9 |
# File 'lib/canopus/block_map.rb', line 9 def remove(id) = @blocks.delete(id) |