Class: SAXMachine::SAXConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sax-machine/sax_config.rb,
lib/sax-machine/sax_element_config.rb,
lib/sax-machine/sax_collection_config.rb

Defined Under Namespace

Classes: CollectionConfig, ElementConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSAXConfig

Returns a new instance of SAXConfig.



8
9
10
11
# File 'lib/sax-machine/sax_config.rb', line 8

def initialize
  @top_level_elements  = {}
  @collection_elements = {}
end

Instance Attribute Details

#collection_elementsObject (readonly)

Returns the value of attribute collection_elements.



6
7
8
# File 'lib/sax-machine/sax_config.rb', line 6

def collection_elements
  @collection_elements
end

#top_level_elementsObject (readonly)

Returns the value of attribute top_level_elements.



6
7
8
# File 'lib/sax-machine/sax_config.rb', line 6

def top_level_elements
  @top_level_elements
end

Instance Method Details

#add_collection_element(name, options) ⇒ Object



18
19
20
21
# File 'lib/sax-machine/sax_config.rb', line 18

def add_collection_element(name, options)
  @collection_elements[name.to_s] ||= []
  @collection_elements[name.to_s] << CollectionConfig.new(name, options)
end

#add_top_level_element(name, options) ⇒ Object



13
14
15
16
# File 'lib/sax-machine/sax_config.rb', line 13

def add_top_level_element(name, options)
  @top_level_elements[name.to_s] ||= []
  @top_level_elements[name.to_s] << ElementConfig.new(name, options)
end

#collection_config(name, nsstack) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sax-machine/sax_config.rb', line 23

def collection_config(name, nsstack)
  prefix, name = name.split(COLON, 2)
  prefix, name = nil, prefix unless name  # No prefix
  namespace = nsstack[prefix]

  return nil unless (a = @collection_elements[name.to_s])
  a.detect { |ce|
    ce.name.to_s == name.to_s &&
    ce.xmlns_match?(namespace)
  }
end

#element_config_for_tag(name, attrs, nsstack) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sax-machine/sax_config.rb', line 44

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

  return nil unless (a = @top_level_elements[name.to_s])
  a.detect do |element_config|
    element_config.xmlns_match?(namespace) &&
    element_config.attrs_match?(attrs)
  end
end

#element_configs_for_attribute(name, attrs) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/sax-machine/sax_config.rb', line 35

def element_configs_for_attribute(name, attrs)
  name = name.split(COLON, 2).last

  return [] unless (a = @top_level_elements[name.to_s])
  a.select do |element_config|
    element_config.has_value_and_attrs_match?(attrs)
  end
end