julien51-sax-machine 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sax-machine.rb CHANGED
@@ -7,5 +7,5 @@ require "sax-machine/sax_handler"
7
7
  require "sax-machine/sax_config"
8
8
 
9
9
  module SAXMachine
10
- VERSION = "0.0.17"
10
+ VERSION = "0.0.18"
11
11
  end
@@ -6,16 +6,18 @@ module SAXMachine
6
6
  attr_reader :top_level_elements, :collection_elements
7
7
 
8
8
  def initialize
9
- @top_level_elements = []
10
- @collection_elements = []
9
+ @top_level_elements = {}
10
+ @collection_elements = {}
11
11
  end
12
12
 
13
13
  def add_top_level_element(name, options)
14
- @top_level_elements << ElementConfig.new(name, options)
14
+ @top_level_elements[name.to_s] ||= []
15
+ @top_level_elements[name.to_s] << ElementConfig.new(name, options)
15
16
  end
16
17
 
17
18
  def add_collection_element(name, options)
18
- @collection_elements << CollectionConfig.new(name, options)
19
+ @collection_elements[name.to_s] ||= []
20
+ @collection_elements[name.to_s] << CollectionConfig.new(name, options)
19
21
  end
20
22
 
21
23
  def collection_config(name, nsstack)
@@ -23,7 +25,7 @@ module SAXMachine
23
25
  prefix, name = nil, prefix unless name # No prefix
24
26
  namespace = nsstack[prefix]
25
27
 
26
- @collection_elements.detect { |ce|
28
+ (@collection_elements[name.to_s] || []).detect { |ce|
27
29
  ce.name.to_s == name.to_s &&
28
30
  ce.xmlns_match?(namespace)
29
31
  }
@@ -31,8 +33,7 @@ module SAXMachine
31
33
 
32
34
  def element_configs_for_attribute(name, attrs)
33
35
  name = name.split(':', 2).last
34
- @top_level_elements.select do |element_config|
35
- element_config.name == name &&
36
+ (@top_level_elements[name.to_s] || []).select do |element_config|
36
37
  element_config.has_value_and_attrs_match?(attrs)
37
38
  end
38
39
  end
@@ -42,8 +43,7 @@ module SAXMachine
42
43
  prefix, name = nil, prefix unless name # No prefix
43
44
  namespace = nsstack[prefix]
44
45
 
45
- @top_level_elements.detect do |element_config|
46
- element_config.name == name &&
46
+ (@top_level_elements[name.to_s] || []).detect do |element_config|
47
47
  element_config.xmlns_match?(namespace) &&
48
48
  element_config.attrs_match?(attrs)
49
49
  end
@@ -43,11 +43,15 @@ module SAXMachine
43
43
  end
44
44
 
45
45
  def columns
46
- sax_config.top_level_elements
46
+ r = []
47
+ sax_config.top_level_elements.each do |name, ecs|
48
+ r += ecs
49
+ end
50
+ r
47
51
  end
48
52
 
49
53
  def column(sym)
50
- columns.select{|c| c.column == sym}[0]
54
+ sax_config.top_level_elements[sym.to_s][0]
51
55
  end
52
56
 
53
57
  def data_class(sym)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-sax-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix