rexle 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rexle.rb +22 -15
  2. metadata +2 -2
@@ -14,9 +14,9 @@ class Rexle
14
14
 
15
15
  if x then
16
16
  procs = {
17
- String: proc {|x| parse_string(x)},
18
- Array: proc {|x| x},
19
- :"REXML::Document" => proc {|x| scan_doc x.root}
17
+ String: proc {|x| parse_string(x)},
18
+ Array: proc {|x| x},
19
+ :"REXML::Document" => proc {|x| scan_doc x.root}
20
20
  }
21
21
  a = procs[x.class.to_s.to_sym].call(x)
22
22
  @doc = scan_element(*a)
@@ -113,6 +113,7 @@ class Rexle
113
113
  end
114
114
  end
115
115
 
116
+ #a.shift # added by jr 171110
116
117
  rlist
117
118
  end
118
119
 
@@ -127,6 +128,10 @@ class Rexle
127
128
 
128
129
  def children=(a) @child_elements = a end
129
130
 
131
+ def element(s)
132
+ self.xpath(s).first
133
+ end
134
+
130
135
  def text(s='')
131
136
  s.empty? ? @value : self.xpath(s).first.value
132
137
  end
@@ -236,9 +241,9 @@ class Rexle
236
241
 
237
242
  if x then
238
243
  procs = {
239
- String: proc {|x| parse_string(x)},
240
- Array: proc {|x| x},
241
- :"REXML::Document" => proc {|x| scan_doc x.root}
244
+ String: proc {|x| parse_string(x)},
245
+ Array: proc {|x| x},
246
+ :"REXML::Document" => proc {|x| scan_doc x.root}
242
247
  }
243
248
  a = procs[x.class.to_s.to_sym].call(x)
244
249
  else
@@ -249,6 +254,16 @@ class Rexle
249
254
  self
250
255
  end
251
256
 
257
+ def element(xpath) @doc.element(xpath) end
258
+ def text(xpath) @doc.text(xpath) end
259
+ def root() @doc end
260
+ def xml()
261
+ body = scan_print(self.root.children).join
262
+ "<%s>%s</%s>" % [self.root.name, body, self.root.name]
263
+ end
264
+
265
+ private
266
+
252
267
  def parse_string(x)
253
268
 
254
269
  # check if the XML string is a dynarex document
@@ -271,14 +286,6 @@ class Rexle
271
286
  end
272
287
 
273
288
  end
274
-
275
- def root() @doc end
276
- def xml()
277
- body = scan_print(self.root.children).join
278
- "<%s>%s</%s>" % [self.root.name, body, self.root.name]
279
- end
280
-
281
- private
282
289
 
283
290
  def scan_element(name, value, attributes, *children)
284
291
  element = Element.new(name, value, attributes)
@@ -310,4 +317,4 @@ class Rexle
310
317
  [node.name, node.text.to_s, attributes, *children]
311
318
  end
312
319
 
313
- end
320
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-11-17 00:00:00 +00:00
12
+ date: 2010-11-18 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency