Class: FormKeeper::Rule::Criteria::Checkbox

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(criteria) ⇒ Checkbox

Returns a new instance of Checkbox.



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/formkeeper.rb', line 558

def initialize(criteria)
  if criteria.has_key?(:default)
    default = criteria.delete :default
    case default
    when Array
      @default = default.collect(&:to_s)
    else
      @default = [default.to_s]
    end
  else
    @default = []
  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
  if criteria.has_key?(:count)
    count = criteria.delete :count
    case count
    when Fixnum
      @count = Range.new(count, count)
    when Range
      @count = count
    else
      raise ArgumentError.new 'invalid :count'
    end
  else
    @count = nil
  end
  @constraints = criteria
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



557
558
559
# File 'lib/formkeeper.rb', line 557

def constraints
  @constraints
end

#countObject (readonly)

Returns the value of attribute count.



557
558
559
# File 'lib/formkeeper.rb', line 557

def count
  @count
end

#defaultObject (readonly)

Returns the value of attribute default.



557
558
559
# File 'lib/formkeeper.rb', line 557

def default
  @default
end

#filtersObject (readonly)

Returns the value of attribute filters.



557
558
559
# File 'lib/formkeeper.rb', line 557

def filters
  @filters
end