Class: SAXMachine::SAXConfig
- Inherits:
-
Object
- Object
- SAXMachine::SAXConfig
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
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_elements ⇒ Object
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_elements ⇒ Object
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
|
# File 'lib/sax-machine/sax_config.rb', line 23
def collection_config(name, nsstack)
prefix, name = name.split(':', 2)
prefix, name = nil, prefix unless name namespace = nsstack[prefix]
(@collection_elements[name.to_s] || []).detect { |ce|
ce.name.to_s == name.to_s &&
ce.xmlns_match?(namespace)
}
end
|
#element_config_for_tag(name, attrs, nsstack) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/sax-machine/sax_config.rb', line 41
def element_config_for_tag(name, attrs, nsstack)
prefix, name = name.split(':', 2)
prefix, name = nil, prefix unless name namespace = nsstack[prefix]
(@top_level_elements[name.to_s] || []).detect do |element_config|
element_config.xmlns_match?(namespace) &&
element_config.attrs_match?(attrs)
end
end
|
#element_configs_for_attribute(name, attrs) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/sax-machine/sax_config.rb', line 34
def element_configs_for_attribute(name, attrs)
name = name.split(':', 2).last
(@top_level_elements[name.to_s] || []).select do |element_config|
element_config.has_value_and_attrs_match?(attrs)
end
end
|