Class: FormKeeper::Rule::Criteria::Combination

Inherits:
Object
  • Object
show all
Defined in:
lib/formkeeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(criteria) ⇒ Combination

Returns a new instance of Combination.



605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/formkeeper.rb', line 605

def initialize(criteria)
  if criteria.has_key?(:fields)
    fields = criteria.delete(:fields)
    if fields.kind_of?(Array) && fields.size >= 2
      @fields = fields.collect(&:to_sym)
    else
      raise ArgumentError.new("combination rule requires :fields as array which include 2 fields at lease")
    end
  else
    raise ArgumentError.new("combination rule requires :fields")
  end
  if criteria.has_key?(:filters)
    filters = criteria.delete :filters
    case filters
    when Array
      @filters = filters.collect(&:to_sym)
    when String
      @filters = [filters.to_sym]
    when Symbol
      @filters = [filters]
    else
      raise ArgumentError.new 'invalid :filters'
    end
  else
    @filters = []
  end
  constraint = criteria.shift
  if constraint.nil?
    raise ArgumentError.new 'constraint not found'
  else
    @constraint = constraint[0]
    @arg = constraint[1]
  end
end

Instance Attribute Details

#argObject (readonly)

Returns the value of attribute arg.



604
605
606
# File 'lib/formkeeper.rb', line 604

def arg
  @arg
end

#constraintObject (readonly)

Returns the value of attribute constraint.



604
605
606
# File 'lib/formkeeper.rb', line 604

def constraint
  @constraint
end

#fieldsObject (readonly)

Returns the value of attribute fields.



604
605
606
# File 'lib/formkeeper.rb', line 604

def fields
  @fields
end

#filtersObject (readonly)

Returns the value of attribute filters.



604
605
606
# File 'lib/formkeeper.rb', line 604

def filters
  @filters
end