superfeedr-sax-machine 0.0.22.2 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,3 +10,6 @@ require "sax-machine/sax_event_recorder"
10
10
  module SAXMachine
11
11
  VERSION = "0.0.21"
12
12
  end
13
+
14
+ EMPTY_STRING = ''
15
+ COLON = ':'
@@ -1,16 +1,19 @@
1
1
  module SAXMachine
2
2
  class NSStack < Hash
3
- def initialize(parent=nil, attrs=[])
3
+ XMLNS = 'xmlns'
4
+
5
+ def initialize(parent=nil, attrs=nil)
4
6
  # Initialize
5
7
  super()
6
8
  @parent = parent
7
9
 
10
+ return self unless attrs
8
11
  # Parse attributes
9
12
  attrs.each do |attr|
10
13
  if attr.kind_of?(Array)
11
14
  k, v = attr
12
15
  case k
13
- when 'xmlns' then self[''] = v
16
+ when XMLNS then self[EMPTY_STRING] = v
14
17
  when /^xmlns:(.+)/ then self[$1] = v
15
18
  end
16
19
  end
@@ -27,7 +30,7 @@ module SAXMachine
27
30
  @parent[name]
28
31
  else
29
32
  # Undefined, empty namespace
30
- ''
33
+ EMPTY_STRING
31
34
  end
32
35
  end
33
36
 
@@ -15,16 +15,16 @@ module SAXMachine
15
15
  else nil
16
16
  end
17
17
  @default_xmlns = options[:default_xmlns]
18
- if @default_xmlns && @xmlns && !@xmlns.include?('')
19
- @xmlns << ''
18
+ if @default_xmlns && @xmlns && !@xmlns.include?(EMPTY_STRING)
19
+ @xmlns << EMPTY_STRING
20
20
  end
21
21
  @record_events = options[:events]
22
22
  end
23
23
 
24
24
  def handler(nsstack)
25
- if @default_xmlns && (nsstack.nil? || nsstack[''] == '')
25
+ if @default_xmlns && (nsstack.nil? || nsstack[EMPTY_STRING] == EMPTY_STRING)
26
26
  nsstack = NSStack.new(nsstack, nsstack)
27
- nsstack[''] = @default_xmlns
27
+ nsstack[EMPTY_STRING] = @default_xmlns
28
28
  end
29
29
  unless @record_events
30
30
  SAXHandler.new(@class.new, nsstack)
@@ -21,29 +21,33 @@ module SAXMachine
21
21
  end
22
22
 
23
23
  def collection_config(name, nsstack)
24
- prefix, name = name.split(':', 2)
24
+ prefix, name = name.split(COLON, 2)
25
25
  prefix, name = nil, prefix unless name # No prefix
26
26
  namespace = nsstack[prefix]
27
27
 
28
- (@collection_elements[name.to_s] || []).detect { |ce|
28
+ return nil unless (a = @collection_elements[name.to_s])
29
+ a.detect { |ce|
29
30
  ce.name.to_s == name.to_s &&
30
31
  ce.xmlns_match?(namespace)
31
32
  }
32
33
  end
33
34
 
34
35
  def element_configs_for_attribute(name, attrs)
35
- name = name.split(':', 2).last
36
- (@top_level_elements[name.to_s] || []).select do |element_config|
36
+ name = name.split(COLON, 2).last
37
+
38
+ return [] unless (a = @top_level_elements[name.to_s])
39
+ a.select do |element_config|
37
40
  element_config.has_value_and_attrs_match?(attrs)
38
41
  end
39
42
  end
40
43
 
41
44
  def element_config_for_tag(name, attrs, nsstack)
42
- prefix, name = name.split(':', 2)
45
+ prefix, name = name.split(COLON, 2)
43
46
  prefix, name = nil, prefix unless name # No prefix
44
47
  namespace = nsstack[prefix]
45
48
 
46
- (@top_level_elements[name.to_s] || []).detect do |element_config|
49
+ return nil unless (a = @top_level_elements[name.to_s])
50
+ a.detect do |element_config|
47
51
  element_config.xmlns_match?(namespace) &&
48
52
  element_config.attrs_match?(attrs)
49
53
  end
@@ -52,7 +52,15 @@ module SAXMachine
52
52
 
53
53
  def attrs_match?(attrs)
54
54
  if @with
55
- @with == (@with & attrs)
55
+ if attrs.nil?
56
+ if @with.empty?
57
+ true
58
+ else
59
+ false
60
+ end
61
+ else
62
+ @with == (@with & attrs)
63
+ end
56
64
  else
57
65
  true
58
66
  end
@@ -10,15 +10,15 @@ module SAXMachine
10
10
  @events[1..-2]
11
11
  end
12
12
 
13
- def start_element(name, attrs = [])
13
+ def start_element(name, attrs = nil)
14
14
  @nsstack = NSStack.new(@nsstack, attrs)
15
- prefix, name = name.split(':', 2)
15
+ prefix, name = name.split(COLON, 2)
16
16
  prefix, name = nil, prefix unless name
17
17
  @events << [:start_element, @nsstack[prefix], name, attrs]
18
18
  end
19
19
 
20
20
  def end_element(name)
21
- prefix, name = name.split(':', 2)
21
+ prefix, name = name.split(COLON, 2)
22
22
  prefix, name = nil, prefix unless name
23
23
  @events << [:end_element, @nsstack[prefix], name]
24
24
  @nsstack = @nsstack.pop
@@ -14,7 +14,11 @@ module SAXMachine
14
14
  if parsing_collection?
15
15
  @collection_handler.characters(string)
16
16
  elsif @element_config
17
- @value << string
17
+ if !@value || @value == EMPTY_STRING
18
+ @value = string
19
+ else
20
+ @value << string
21
+ end
18
22
  end
19
23
  end
20
24
 
@@ -22,10 +26,10 @@ module SAXMachine
22
26
  characters(string)
23
27
  end
24
28
 
25
- def start_element(name, attrs = [])
29
+ def start_element(name, attrs = nil)
26
30
 
27
31
  @name = name
28
- @attrs = attrs.map { |a| SAXHandler.decode_xml(a) }
32
+ @attrs = attrs ? attrs.map { |a| SAXHandler.decode_xml(a) } : nil
29
33
  @nsstack = NSStack.new(@nsstack, @attrs)
30
34
 
31
35
  if parsing_collection?
@@ -46,7 +50,7 @@ module SAXMachine
46
50
  end
47
51
 
48
52
  def end_element(name)
49
- if parsing_collection? && @collection_config.name == name.split(':').last
53
+ if parsing_collection? && @collection_config.name == name.split(COLON).last
50
54
  @collection_handler.end_element(name)
51
55
  @object.send(@collection_config.accessor) << @collection_handler.object
52
56
  reset_current_collection
@@ -85,7 +89,7 @@ module SAXMachine
85
89
  end
86
90
 
87
91
  def set_element_config_for_element_value
88
- @value = ""
92
+ @value = EMPTY_STRING
89
93
  @element_config = sax_config.element_config_for_tag(@name, @attrs, @nsstack)
90
94
  end
91
95
 
metadata CHANGED
@@ -1,32 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superfeedr-sax-machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22.2
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix
8
- - Stephan Maka
8
+ - astro
9
9
  - julien51
10
10
  - superfeedr
11
+ - yakischloba
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
15
 
15
- date: 2009-11-16 00:00:00 +01:00
16
+ date: 2009-01-27 00:00:00 +01:00
16
17
  default_executable:
17
18
  dependencies:
18
19
  - !ruby/object:Gem::Dependency
19
- name: superfeedr-nokogiri
20
+ name: nokogiri
20
21
  type: :runtime
21
22
  version_requirement:
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ">="
25
+ - - ">"
25
26
  - !ruby/object:Gem::Version
26
- version: 1.4.0.20091116183308
27
+ version: 0.0.0
27
28
  version:
28
29
  description:
29
- email: paul@pauldix.net stephan@spaceboyz.net
30
+ email:
30
31
  executables: []
31
32
 
32
33
  extensions: []
@@ -48,7 +49,7 @@ files:
48
49
  - spec/spec_helper.rb
49
50
  - spec/sax-machine/sax_document_spec.rb
50
51
  has_rdoc: true
51
- homepage: http://github.com/pauldix/sax-machine
52
+ homepage: http://github.com/julien51/sax-machine
52
53
  licenses: []
53
54
 
54
55
  post_install_message: