Sha256: 2b4e64514449a2f6e7daba8ee2532ca27ad5d7e212d7b3db66653261b490f33f

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

module Rulz
  module Conditions
    module String
      
      def self.load_conditions(reciever, attr)
        reciever.class_eval do
          define_rulz do
            attribute attr do
              condition "does not match" do |regex|
                send(attr).scan(regex).empty?
              end
              condition "matches" do |regex|
                opposite_of "does not match", regex
              end
              condition "like" do |other|
                send(attr).downcase == other.downcase
              end
              condition "not like" do |other|
                opposite_of "like", other
              end
            end
          end
        end
      end
      
      def self.included(base)
        base.class_eval do
          include Rulz::Conditions::Container
          define_rulz do
            condition "does not match" do |regex|
              it.scan(regex).empty?
            end
            condition "matches" do |regex|
              opposite_of "does not match", regex
            end
            condition "like" do |other|
              it.downcase == other.downcase
            end
            condition "not like" do |other|
              opposite_of "like", other
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rulz-1.0.2 lib/rulz/conditions/string.rb
rulz-1.0.1 lib/rulz/conditions/string.rb
rulz-1.0.0 lib/rulz/conditions/string.rb