Sha256: e9e8cdeffdd0c9d1335eb48489153972abee506c607f89d905f0c58f29dfa7f1

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 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 @default_xmlns && (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

2 entries across 2 versions & 2 rubygems

Version Path
astro-sax-machine-0.0.20 lib/sax-machine/sax_collection_config.rb
julien51-sax-machine-0.0.20 lib/sax-machine/sax_collection_config.rb