Sha256: b434ce899ea340ad1f4074a2fbbb1496b32609ca3cbb818e60e9846cdd106b09

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 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
              condition "equals" do |other|
                send(attr) == other
              end        
              condition "does not equal" do |other|
                opposite_of "equal to", other
              end              
            end
          end
        end
      end
      
      def self.included(base)
        base.class_eval do
          include Rulz::Conditions::Container
          define_rulz do
            condition "equals" do |other|
              send(attr) == other
            end
            condition "does not equal" do |other|
              opposite_of "equal to", other
            end              
            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.5 lib/rulz/conditions/string.rb
rulz-1.0.4 lib/rulz/conditions/string.rb
rulz-1.0.3 lib/rulz/conditions/string.rb