class Draught::Transformations::Composer
Attributes
transforms[R]
Public Class Methods
compose(*transforms)
click to toggle source
# File lib/draught/transformations/composer.rb, line 6 def self.compose(*transforms) new(transforms).composition end
new(transforms)
click to toggle source
# File lib/draught/transformations/composer.rb, line 12 def initialize(transforms) @transforms = transforms end
Public Instance Methods
coalesced_transforms()
click to toggle source
# File lib/draught/transformations/composer.rb, line 20 def coalesced_transforms return [] if transforms.empty? start_transforms = flattened_transforms finished = start_transforms.shift(1) return finished if start_transforms.empty? start_transforms.each do |next_transform| coalesce_pair(finished.pop, next_transform).each do |coalesced_transform| finished << coalesced_transform end end finished end
composition()
click to toggle source
# File lib/draught/transformations/composer.rb, line 16 def composition Composition.new(coalesced_transforms) end
flattened_transforms()
click to toggle source
# File lib/draught/transformations/composer.rb, line 34 def flattened_transforms transforms.flat_map { |transform| transform.to_transform.transforms } end
Private Instance Methods
coalesce_pair(first, second)
click to toggle source
# File lib/draught/transformations/composer.rb, line 42 def coalesce_pair(first, second) begin [first.coalesce(second)] rescue TypeError [first, second] end end