cs3b/kameleon

see number of things where things could be defined in defined areas

Opened this issue · 0 comments

cs3b commented

e.g.

  see 1 => :row

solution might look like

   class Quantity
        attr_reader :conditions
        attr_reader :quantity

        def initialize(quantity, params)
          @conditions = []
          @quantity = quantity
          parse_params(params)
        end

        private

        def parse_params(params)
          if params === Array && params.first == Array
            params.each { |param| parse_params(param) }
          elsif params.is_a?(Symbol)
            parse_params(Kameleon::DSL::Context::Scope.new(params).selector)
          else
            #! refactor
            selector = prepare_query(params).selector
            conditions << Condition.new(prepare_method(selector), selector.last, :count => quantity)
          end
        end

        def prepare_query(selector)
          Context::Scope.new(selector)
        end

        #! refactor - delagate to Context::Scope class
        def prepare_method(query)
          query.first == :xpath ?
              :have_xpath :
              :have_css
        end
      end