Sha256: d3e82d97198071781819c25973f89ce22dfd11395b7168df3b6191434aa4f8ec

Contents?: true

Size: 757 Bytes

Versions: 2

Compression:

Stored size: 757 Bytes

Contents

module Repeatable
  module Expression
    class Base
      def self.===(other)
        case other
        when Class
          other.ancestors.include?(self)
        else
          super
        end
      end

      def include?(_date)
        fail(
          NotImplementedError,
          "Don't use Expression::Base directly. Subclasses must implement `#include?`"
        )
      end

      def to_h
        fail(
          NotImplementedError,
          "Don't use Expression::Base directly. Subclasses must implement `#to_h`"
        )
      end

      private

      def hash_key
        self.class.name.split('::').last
          .gsub(/(?<!\b)[A-Z]/) { "_#{Regexp.last_match[0]}" }
          .downcase
          .to_sym
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
repeatable-0.5.0 lib/repeatable/expression/base.rb
repeatable-0.4.0 lib/repeatable/expression/base.rb