Sha256: c059216b1552b68d32031710ae34c8ce92b6859f86faaf282546c1c7946cf0ad

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require "sax-machine/sax_element_config"
require "sax-machine/sax_collection_config"

module SAXMachine
  class SAXConfig
    attr_reader :top_level_elements, :collection_elements

    def initialize
      @top_level_elements  = []
      @collection_elements = []
    end

    def add_top_level_element(name, options)
      @top_level_elements << ElementConfig.new(name, options)
    end

    def add_collection_element(name, options)
      @collection_elements << CollectionConfig.new(name, options)
    end

    def collection_config(name)
      @collection_elements.detect { |ce| ce.name.to_s == name.to_s }
    end

    def element_configs_for_attribute(name, attrs)
      @top_level_elements.select do |element_config|
        element_config.name == name &&
        element_config.has_value_and_attrs_match?(attrs)
      end
    end

    def element_config_for_tag(name, attrs, nsstack)
      prefix, name = name.split(':', 2)
      prefix, name = nil, prefix unless name  # No prefix
      namespace = nsstack[prefix]

      @top_level_elements.detect do |element_config|
        element_config.name == name &&
        element_config.xmlns_match?(namespace) &&
        element_config.attrs_match?(attrs)
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
astro-sax-machine-0.0.15 lib/sax-machine/sax_config.rb
julien51-sax-machine-0.0.15 lib/sax-machine/sax_config.rb
julien51-sax-machine-0.0.16 lib/sax-machine/sax_config.rb