Sha256: 8fb2a6ea1b8dff98f19b68fde643bb7a51248f24774a454977476ff0838ec3f8

Contents?: true

Size: 945 Bytes

Versions: 13

Compression:

Stored size: 945 Bytes

Contents

# encoding: utf-8
module Middleman
  module Presentation
    module Transformers
      # Remove duplicates slides from list
      class RemoveDuplicateSlides
        private

        attr_reader :additional_slides, :raise_error

        public

        def initialize(additional_slides: [], raise_error: false)
          @additional_slides = additional_slides
          @raise_error       = raise_error
        end

        def transform(slides)
          temp_slides = (Array(slides) + Array(additional_slides)).uniq

          duplicate_slides = temp_slides.each_with_object([]) do |e, a|
            a << slides.select { |s| e.similar?(s) && !e.eql?(s) }
          end.flatten

          fail ArgumentError, Middleman::Presentation.t('errors.duplicate_slide_names', slide_names: duplicate_slides.map(&:file_name).to_list) if !duplicate_slides.blank? && raise_error

          slides - duplicate_slides
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
middleman-presentation-core-0.17.7 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.17.6 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.17.5 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.17.2 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.17.1 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.17.0 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.3 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.2 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.0 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.0.rc2 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.0.rc1 lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.0.beta lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb
middleman-presentation-core-0.16.0.alpha lib/middleman-presentation-core/transformers/remove_duplicate_slides.rb