Sha256: 3388c907c83cb22762f834aa82a600848aec65efe348d37160f9a19e1b762b66

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8
module Middleman
  module Presentation
    # All methods needed to compare slides
    module ComparableSlide
      include Comparable

      # Needs to be implemented to make the other methods work
      def path
        fail MethodNotImplemented
      end

      # Needs to be implemented to make the other methods work
      def base_name
        fail MethodNotImplemented
      end

      # Needs to be implemented to make the other methods work
      def group
        fail MethodNotImplemented
      end

      # @private
      def <=>(other)
        path <=> other.path
      end

      # @private
      def eql?(other)
        path.eql? other.path
      end

      # Is slide similar to another slide
      def similar?(other)
        return true if eql? other

        base_name?(other.base_name) && group?(other.group)
      end

      # @private
      def hash
        path.hash
      end

      # Checks if slide is in group
      def group?(g)
        group == g
      end

      # Check if string/regex matches path
      def match?(string_or_regex)
        regex = if string_or_regex.is_a? String
                  Regexp.new(string_or_regex)
                else
                  string_or_regex
                end

        # rubocop:disable Style/CaseEquality:
        regex === relative_path.to_s
        # rubocop:enable Style/CaseEquality:
      end

      # Check if basename is equal
      def base_name?(b)
        base_name == b
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
middleman-presentation-0.15.8 lib/middleman-presentation/comparable_slide.rb
middleman-presentation-0.15.7 lib/middleman-presentation/comparable_slide.rb
middleman-presentation-0.15.6 lib/middleman-presentation/comparable_slide.rb
middleman-presentation-0.15.5 lib/middleman-presentation/comparable_slide.rb