Method: Spider::Model::Condition#initialize

Defined in:
lib/spiderfw/model/condition.rb

#initialize(*params, &proc) ⇒ Condition

Instantiates a new Condition, with :and conjunction. If given a Hash, will set all keys = values. If given multiple params, will convert each to a Condition if needed, and append them to the returned instance. If a block is given, it will be processed by #parse_block



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/spiderfw/model/condition.rb', line 108

def initialize(*params, &proc)
    @conjunction = :and
    @comparisons = {}
    @subconditions = []
    params.reject!{ |p| p.nil? }
    if params[0].is_a?(Proc)
        params[0] = params[0].call
    end
    if (params.length == 1 && params[0].is_a?(Hash) && !params[0].is_a?(Condition))
        params[0].each do |k, v|
            set(k, '=', v)
        end
    else
        # FIXME: must have an instantiate method
        params.each{ |item| self << (item.is_a?(self.class) ? item : self.class.new(item)) } 
    end
    parse_block(&proc) if (block_given?)
end