ox 2.13.1 → 2.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,6 +44,7 @@ module Ox
44
44
  @nodes = []
45
45
  end
46
46
  alias name value
47
+ alias name= value=
47
48
 
48
49
  # Returns the Element's nodes array. These are the sub-elements of this
49
50
  # Element.
@@ -114,17 +115,8 @@ module Ox
114
115
  # matching name will be yielded to. If the cond is a Hash then the
115
116
  # keys-value pairs in the cond must match the child attribute values with
116
117
  # the same keys. Any other cond type will yield to nothing.
117
- def each(cond=nil)
118
- if cond.nil?
119
- nodes.each { |n| yield(n) }
120
- else
121
- cond = cond.to_s if cond.is_a?(Symbol)
122
- if cond.is_a?(String)
123
- nodes.each { |n| yield(n) if n.is_a?(Element) && cond == n.name }
124
- elsif cond.is_a?(Hash)
125
- nodes.each { |n| yield(n) if n.is_a?(Element) && n.attr_match(cond) }
126
- end
127
- end
118
+ def each(cond=nil, &block)
119
+ build_enumerator(cond).each(&block)
128
120
  end
129
121
 
130
122
  # Returns an array of Nodes or Strings that correspond to the locations
@@ -412,6 +404,24 @@ module Ox
412
404
 
413
405
  private
414
406
 
407
+ # Builds an enumerator for use in `#each` call
408
+ #
409
+ # - +cond+ [Hash, String, nil] an element filter
410
+ def build_enumerator(cond)
411
+ if cond.nil?
412
+ nodes.each
413
+ else
414
+ cond = cond.to_s if cond.is_a?(Symbol)
415
+ Enumerator.new do |yielder|
416
+ if cond.is_a?(String)
417
+ nodes.each { |n| yielder.yield(n) if n.is_a?(Element) && cond == n.name }
418
+ elsif cond.is_a?(Hash)
419
+ nodes.each { |n| yielder.yield(n) if n.is_a?(Element) && n.attr_match(cond) }
420
+ end
421
+ end
422
+ end
423
+ end
424
+
415
425
  # Removes recursively children for nodes and sub_nodes
416
426
  #
417
427
  # - +found+ [Array] An array of Ox::Element
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.13.1'
4
+ VERSION = '2.14.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.1
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-30 00:00:00.000000000 Z
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n\nOptimized
14
14
  XML (Ox), as the name implies was written to provide speed optimized\nXML handling.
@@ -76,7 +76,7 @@ homepage: http://www.ohler.com/ox
76
76
  licenses:
77
77
  - MIT
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message:
80
80
  rdoc_options:
81
81
  - "--main"
82
82
  - README.md
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.1.2
102
- signing_key:
101
+ rubygems_version: 3.2.3
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: A fast XML parser and object serializer.
105
105
  test_files: []