Sha256: 56f1ec04eb3d1e2f8b4f7e51dfc2202eeaf44bbc66c1390f98a8cfe6a24d6307

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

module SAXMachine
  class SAXConfig
    
    class ElementConfig
      attr_reader :name, :setter
      
      def initialize(name, options)
        @name = name.to_s
        
        if options.has_key?(:with)
          # for faster comparisons later
          @with = options[:with].to_a.flatten.collect {|o| o.to_s}
        else
          @with = nil
        end
        
        if options.has_key?(:value)
          @value = options[:value].to_s
        else
          @value = nil
        end
        
        @as = options[:as]
        @collection = options[:collection]
        
        if @collection
          @setter = "add_#{options[:as]}"
        else
          @setter = "#{@as}="
        end
      end

      def value_from_attrs(attrs)
        attrs.index(@value) ? attrs[attrs.index(@value) + 1] : nil
      end
      
      def attrs_match?(attrs)
        if @with
          @with == (@with & attrs)
        else
          true
        end
      end
      
      def has_value_and_attrs_match?(attrs)
        !@value.nil? && attrs_match?(attrs)
      end
      
      def collection?
        @collection
      end
    end
    
  end
end

Version data entries

4 entries across 4 versions & 4 rubygems

Version Path
UnderpantsGnome-sax-machine-0.0.13 lib/sax-machine/sax_element_config.rb
astro-sax-machine-0.0.12.20090419 lib/sax-machine/sax_element_config.rb
julien51-sax-machine-0.0.13 lib/sax-machine/sax_element_config.rb
pauldix-sax-machine-0.0.13 lib/sax-machine/sax_element_config.rb