rexle 0.4.0 → 0.4.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 +12 -0
  2. metadata +2 -2
data/lib/rexle.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  # file: rexle.rb
4
4
 
5
+ require 'rexml/document'
5
6
  require 'rexleparser'
7
+ include REXML
6
8
 
7
9
  class Rexle
8
10
 
@@ -10,6 +12,7 @@ class Rexle
10
12
  procs = {
11
13
  String: proc {|x| RexleParser.new(x).to_a},
12
14
  Array: proc {|x| x}
15
+ REXML::Document: proc {|x| scan_doc x.root}
13
16
  }
14
17
  a = procs[x.class.to_s.to_sym].call(x)
15
18
  @doc = scan_element(*a)
@@ -241,5 +244,14 @@ class Rexle
241
244
  end
242
245
 
243
246
  def count(path) @doc.xpath(path).flatten.compact.length end
247
+
248
+ # scan a rexml doc
249
+ #
250
+ def scan_doc(node)
251
+ children = node.elements.map {|child| scan_doc child}
252
+ attributes = node.attributes.inject({}){|r,x| r.merge(Hash[*x])}
253
+ [node.name, node.text.to_s, attributes, *children]
254
+ end
255
+
244
256
 
245
257
  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.4.0
4
+ version: 0.4.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-14 00:00:00 +00:00
12
+ date: 2010-11-16 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency