oga 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1ef8ce9859d513dc0b7aa68284d825e3f50d548
4
- data.tar.gz: f463aba9ea8634735834f8c31323893b5dd48f00
3
+ metadata.gz: 0884bc981b96ff1504e09e5c100c5b63dbf5f912
4
+ data.tar.gz: e0bcfded6267dc24bd995a32541537f8f6766566
5
5
  SHA512:
6
- metadata.gz: 81e745c8341fa7b6cae1f7a9ddbd5d066cacb2ce547ee48680be8d2e2b4898fcaba7e2aa6c4ee16dc7169785f7fd24ca31bed725e913f6fe1abd1e50bffc2caf
7
- data.tar.gz: 994e333deff715e9172cdddcd876c99d212750cb4b59f41e93765cccef9dc3df6e0e851520c098e3308f8fdcaee0317cd17099e1e2324e6cdccecd5c7c6054be
6
+ metadata.gz: 61ea4f71bc78a2162671b255091dd6568c36485925e334db8a23a88a45ba43437c78c718ab23c95b659251dd7adf5ffbc1dacf37c03cb07af075f4a64f676196
7
+ data.tar.gz: 97c97b8d8ab767236547d9ca4998ea3ad62d4d06ee22ca34d4248791d28e0ca51ee5dabfd76c188de1ad8d9647af8d24b60b364d05b0cac53bf74d8bda5efd62
data/lib/oga/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oga
2
- VERSION = '1.2.2'
2
+ VERSION = '1.2.3'
3
3
  end # Oga
@@ -42,10 +42,15 @@ module Oga
42
42
  # @param [Oga::XML::NodeSet] owner The owner of the set.
43
43
  #
44
44
  def initialize(nodes = [], owner = nil)
45
- @nodes = nodes
46
- @owner = owner
45
+ @nodes = nodes
46
+ @owner = owner
47
+ @existing = {}
47
48
 
48
- @nodes.each { |node| take_ownership(node) } if owner
49
+ @nodes.each do |node|
50
+ mark_existing(node)
51
+
52
+ take_ownership(node) if @owner
53
+ end
49
54
  end
50
55
 
51
56
  ##
@@ -103,11 +108,13 @@ module Oga
103
108
  # @param [Oga::XML::Node] node
104
109
  #
105
110
  def push(node)
106
- return if @nodes.include?(node)
111
+ return if exists?(node)
107
112
 
108
113
  @nodes << node
109
114
 
110
- take_ownership(node)
115
+ mark_existing(node)
116
+
117
+ take_ownership(node) if @owner
111
118
  end
112
119
 
113
120
  alias_method :<<, :push
@@ -118,11 +125,13 @@ module Oga
118
125
  # @param [Oga::XML::Node] node
119
126
  #
120
127
  def unshift(node)
121
- return if @nodes.include?(node)
128
+ return if exists?(node)
122
129
 
123
130
  @nodes.unshift(node)
124
131
 
125
- take_ownership(node)
132
+ mark_existing(node)
133
+
134
+ take_ownership(node) if @owner
126
135
  end
127
136
 
128
137
  ##
@@ -133,7 +142,11 @@ module Oga
133
142
  def shift
134
143
  node = @nodes.shift
135
144
 
136
- remove_ownership(node)
145
+ if node
146
+ unmark_existing(node)
147
+
148
+ remove_ownership(node) if @owner
149
+ end
137
150
 
138
151
  node
139
152
  end
@@ -146,7 +159,11 @@ module Oga
146
159
  def pop
147
160
  node = @nodes.pop
148
161
 
149
- remove_ownership(node)
162
+ if node
163
+ unmark_existing(node)
164
+
165
+ remove_ownership(node) if @owner
166
+ end
150
167
 
151
168
  node
152
169
  end
@@ -158,11 +175,13 @@ module Oga
158
175
  # @param [Oga::XML::Node] node
159
176
  #
160
177
  def insert(index, node)
161
- return if @nodes.include?(node)
178
+ return if exists?(node)
162
179
 
163
180
  @nodes.insert(index, node)
164
181
 
165
- take_ownership(node)
182
+ mark_existing(node)
183
+
184
+ take_ownership(node) if @owner
166
185
  end
167
186
 
168
187
  ##
@@ -257,7 +276,11 @@ module Oga
257
276
  def delete(node)
258
277
  removed = @nodes.delete(node)
259
278
 
260
- remove_ownership(removed) if removed
279
+ if removed
280
+ unmark_existing(removed)
281
+
282
+ remove_ownership(removed) if @owner
283
+ end
261
284
 
262
285
  removed
263
286
  end
@@ -317,7 +340,7 @@ module Oga
317
340
  # @param [Oga::XML::Node] node
318
341
  #
319
342
  def take_ownership(node)
320
- node.node_set = self if owner
343
+ node.node_set = self
321
344
  end
322
345
 
323
346
  ##
@@ -328,6 +351,22 @@ module Oga
328
351
  def remove_ownership(node)
329
352
  node.node_set = nil if node.node_set == self
330
353
  end
354
+
355
+ # @param [Oga::XML::Node|Oga::XML::Attribute] node
356
+ # @return [TrueClass|FalseClass]
357
+ def exists?(node)
358
+ @existing.key?(node)
359
+ end
360
+
361
+ # @param [Oga::XML::Node|Oga::XML::Attribute] node
362
+ def mark_existing(node)
363
+ @existing[node] = true
364
+ end
365
+
366
+ # @param [Oga::XML::Node|Oga::XML::Attribute] node
367
+ def unmark_existing(node)
368
+ @existing.delete(node)
369
+ end
331
370
  end # NodeSet
332
371
  end # XML
333
372
  end # Oga
@@ -1691,7 +1691,9 @@ module Oga
1691
1691
  def name_matches?(xml_node, name)
1692
1692
  return false unless xml_node.respond_to?(:name)
1693
1693
 
1694
- name == STAR ? true : xml_node.name == name
1694
+ return true if name == STAR
1695
+
1696
+ xml_node.name == name || xml_node.name.casecmp(name) == 0
1695
1697
  end
1696
1698
 
1697
1699
  ##
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oga
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-14 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 2.4.5
222
+ rubygems_version: 2.4.8
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: Oga is an XML/HTML parser written in Ruby.