roxo 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roxo.rb +14 -4
- data/roxo.gemspec +1 -1
- metadata +3 -3
data/lib/roxo.rb
CHANGED
@@ -8,12 +8,15 @@ class ROXO
|
|
8
8
|
include Comparable
|
9
9
|
|
10
10
|
attr_reader :raw, :name, :value, :children
|
11
|
-
def __attributes; @attributes.sort; end
|
12
11
|
def attributes; @attributes.keys; end
|
13
12
|
def has?(o); !! send(o); end # Boolean. Does this exist?
|
14
13
|
def [](o); @attributes[o.to_s]; end # Only lookup attributes
|
15
14
|
def to_s; @value; end
|
16
15
|
|
16
|
+
def __attributes
|
17
|
+
@attributes.sort.reject{|a|a.to_s =~ /^xmlns/}
|
18
|
+
end
|
19
|
+
|
17
20
|
def initialize(xml)
|
18
21
|
xml = ::LibXML::XML::Parser.string(xml).parse.root unless xml.kind_of?(LibXML::XML::Node)
|
19
22
|
|
@@ -31,13 +34,20 @@ class ROXO
|
|
31
34
|
end # A node is terminal if we can't descend any further
|
32
35
|
|
33
36
|
def <=>(other)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
return z unless (z = self.class <=> other.class).zero?
|
38
|
+
return z unless (z = self.__attributes <=> other.__attributes).zero?
|
39
|
+
return z unless (z = self.value <=> other.value).zero?
|
40
|
+
return z unless (z = self.name <=> other.name).zero?
|
41
|
+
|
37
42
|
nodes = lambda{|obj|obj.children.values.flatten.map{|n|self.class.new(n)}}
|
38
43
|
nodes[self] <=> nodes[other]
|
39
44
|
end
|
40
45
|
|
46
|
+
def ==(o)
|
47
|
+
self.<=>(o) == 0
|
48
|
+
end
|
49
|
+
|
50
|
+
|
41
51
|
def method_missing(sym, *args)
|
42
52
|
if terminal? # Proxy all method calls to the wrapped object.
|
43
53
|
return @value.send(sym, *args)
|
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
|
+
- 7
|
9
|
+
version: 0.1.7
|
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-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|