roxo 0.1.3 → 0.1.5
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.
- data/lib/roxo.rb +7 -8
- data/roxo.gemspec +1 -1
- metadata +3 -3
data/lib/roxo.rb
CHANGED
@@ -3,9 +3,7 @@ require 'libxml'
|
|
3
3
|
|
4
4
|
# Ruby Objects as XML Objects
|
5
5
|
class ROXO
|
6
|
-
instance_methods.each
|
7
|
-
eval "undef #{meth}" unless [:__send__, :__id__, :object_id, :class, :send].include?(meth.to_sym)
|
8
|
-
end
|
6
|
+
(instance_methods - %w{__send__ __id__ object_id class send}).each{|m|eval "undef #{m}"}
|
9
7
|
|
10
8
|
include Comparable
|
11
9
|
|
@@ -22,10 +20,7 @@ class ROXO
|
|
22
20
|
|
23
21
|
@raw, @name, @attributes = xml, xml.name, xml.attributes.to_h
|
24
22
|
@children = xml.children.select(&:element?).group_by{|c|c.name.to_sym}
|
25
|
-
|
26
|
-
text_value = xml.children.select(&:text?).map(&:to_s).reject(&:empty?).join
|
27
|
-
cdata_value = xml.children.select(&:cdata?).map{|c|c.to_s.chomp(']]>').sub('<![CDATA[', '')}.join
|
28
|
-
@value = text_value.empty? ? cdata_value : text_value
|
23
|
+
@value = xml.children.select{|e|e.text? or e.cdata?}.map{|e|e.to_s.chomp(']]>').sub('<![CDATA[','')}.join
|
29
24
|
end
|
30
25
|
|
31
26
|
def inspect
|
@@ -41,7 +36,11 @@ class ROXO
|
|
41
36
|
end
|
42
37
|
|
43
38
|
def method_missing(sym, *args)
|
44
|
-
if
|
39
|
+
if terminal? # Proxy all method calls to the wrapped object.
|
40
|
+
return @value.send(sym, *args)
|
41
|
+
elsif sym.to_s[-1..-1]=="?" # re-dispatch without question mark, interpret result as a boolean.
|
42
|
+
return %w{yes true t y}.include?(send(sym.to_s[0..-2].to_sym, *args).downcase)
|
43
|
+
elsif @children[sym]
|
45
44
|
return self.class.new(@children[sym].first)
|
46
45
|
elsif @attributes[sym.to_s]
|
47
46
|
return @attributes[sym.to_s]
|
data/roxo.gemspec
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Burke Libbey
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-21 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|