Sha256: addb2a2e4a4577804950d692c711171426d6db2b9de0fe8e40990a560734b1d5

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

module SAXMachine
  class SAXConfig
    
    class CollectionConfig
      attr_reader :name
      attr_reader :default_xmlns
      
      def initialize(name, options)
        @name   = name.to_s
        @class  = options[:class]
        @as     = options[:as].to_s
        @xmlns  = case options[:xmlns]
                  when Array then options[:xmlns]
                  when String then [options[:xmlns]]
                  else nil
                  end
        @default_xmlns = options[:default_xmlns]
        if @default_xmlns && @xmlns && !@xmlns.include?('')
          @xmlns << ''
        end
        @record_events = options[:events]
      end
      
      def handler(nsstack)
        if @default_xmlns && (nsstack.nil? || nsstack[''] == '')
          nsstack = NSStack.new(nsstack, nsstack)
          nsstack[''] = @default_xmlns
        end
        unless @record_events
          SAXHandler.new(@class.new, nsstack)
        else
          SAXEventRecorder.new(nsstack)
        end
      end
      
      def accessor
        as
      end
      
      def xmlns_match?(ns)
        @xmlns.nil? || @xmlns.include?(ns)
      end
      
    protected
      
      def as
        @as
      end
      
      def class
        @class || @name
      end      
    end
    
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
julien51-sax-machine-0.0.21 lib/sax-machine/sax_collection_config.rb
superfeedr-sax-machine-0.0.22.2 lib/sax-machine/sax_collection_config.rb
superfeedr-sax-machine-0.0.22.1 lib/sax-machine/sax_collection_config.rb
julien51-sax-machine-0.0.22 lib/sax-machine/sax_collection_config.rb