lib/csl/node.rb in csl-1.3.0 vs lib/csl/node.rb in csl-1.3.1
- old
+ new
@@ -472,15 +472,16 @@
def quotes?
attribute?(:'quotes') && !!(attributes[:'quotes'].to_s =~ /^true$/i)
end
+
def <=>(other)
return nil unless other.is_a?(Node)
- return 1 if other.textnode?
-
- [nodename, attributes, children] <=> [other.nodename, other.attributes, other.children]
+ comparables <=> other.comparables
+ rescue
+ nil
end
# Returns the node' XML tags (including attribute assignments) as an
# array of strings.
def tags
@@ -509,10 +510,22 @@
protected
def match_conditions
end
+ def comparables
+ c = []
+
+ c << nodename
+ c << attributes
+
+ c << (textnode? ? text : '')
+ c << (has_children? ? children : [])
+
+ c
+ end
+
private
def attribute_assignments
attrs = self.class.hide_default_attributes? ?
custom_attributes : attributes.to_hash
@@ -600,16 +613,9 @@
text.nil? || text.empty?
end
def tags
["<#{attribute_assignments.unshift(nodename).join(' ')}>#{to_s}</#{nodename}>"]
- end
-
- def <=>(other)
- return nil unless other.is_a?(Node)
- return -1 unless other.textnode?
-
- [nodename, attributes, text] <=> [other.nodename, other.attributes, other.text]
end
def inspect
"#<#{[self.class.name, text.inspect, *attribute_assignments].join(' ')}>"
end