Class: Canopus::Patch::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/canopus/patch/composite.rb,
sig/canopus.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patches) ⇒ Composite

Returns a new instance of Composite.

Parameters:

  • patches (Array[patch])


5
# File 'lib/canopus/patch/composite.rb', line 5

def initialize(patches) = @patches = patches.freeze

Instance Attribute Details

#patches ⇒ Array[patch] (readonly)

Returns the value of attribute patches.

Returns:

  • (Array[patch])


4
5
6
# File 'lib/canopus/patch/composite.rb', line 4

def patches
  @patches
end

Instance Method Details

#after ⇒ rope

Returns:

  • (rope)


7
# File 'lib/canopus/patch/composite.rb', line 7

def after = patches.last.after

#before ⇒ rope

Returns:

  • (rope)


6
# File 'lib/canopus/patch/composite.rb', line 6

def before = patches.first.before

#compose(other) ⇒ Composite

Parameters:

  • other (patch)

Returns:



11
# File 'lib/canopus/patch/composite.rb', line 11

def compose(other) = self.class.new([*patches, other])

#edits ⇒ Array[Edit]

Returns:



8
# File 'lib/canopus/patch/composite.rb', line 8

def edits = patches.flat_map(&:edits)

#inverse ⇒ Composite

Returns:



10
# File 'lib/canopus/patch/composite.rb', line 10

def inverse = self.class.new(patches.reverse.map(&:inverse))

#map_offset(offset, bias: :right) ⇒ Integer

Parameters:

  • offset (Integer)
  • bias: (bias) (defaults to: :right)

Returns:

  • (Integer)


9
# File 'lib/canopus/patch/composite.rb', line 9

def map_offset(offset, bias: :right) = patches.reduce(offset) { |position, patch| patch.map_offset(position, bias: bias) }