Sha256: c31ff72656e6b9c5a15d577abab6adecec8514ef7a4e8b939fc2d43a2ae0f275

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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
      end
      
      def handler(nsstack)
        if nsstack.nil? || nsstack[''] == ''
          nsstack = NSStack.new(nsstack, nsstack)
          nsstack[''] = @default_xmlns
        end
        SAXHandler.new(@class.new, nsstack)
      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

1 entries across 1 versions & 1 rubygems

Version Path
julien51-sax-machine-0.0.19 lib/sax-machine/sax_collection_config.rb