lib/csl/treelike.rb in csl-1.0.0.pre21 vs lib/csl/treelike.rb in csl-1.0.0.pre22

- old
+ new

@@ -4,11 +4,11 @@ attr_accessor :parent attr_reader :children attr_writer :nodename - protected :parent= + protected :parent= def self.included(base) base.extend(ClassMethods) end @@ -118,13 +118,13 @@ def has_children? !empty? end # @return [Boolean] true if this node has no child nodes; false otherwise. - def empty? - children.empty? - end + def empty? + children.empty? + end # Unlinks the node and all its children from its parent node. Returns # the old parent node or nil. def unlink return nil if root? @@ -210,14 +210,14 @@ parent.nil? end # Add memoized methods. When processing citations, styles will - # typically remain stable; therefore cite processors may opt - # to use memoized versions of the following methods. These - # versions are marked with an exclamation mark as a reminder - # that the return values are cached and potentially outdated. + # typically remain stable; therefore cite processors may opt + # to use memoized versions of the following methods. These + # versions are marked with an exclamation mark as a reminder + # that the return values are cached and potentially outdated. %w{ ancestors descendants siblings root depth }.each do |name| ivar = "@#{name}" define_method("#{name}!") do instance_variable_get(ivar) || send(name) end @@ -259,21 +259,21 @@ else [] end end - def constantize_nodename(name) - return constantize(name) if respond_to?(:constantize) + def constantize_nodename(name) + return constantize(name) if respond_to?(:constantize) klass = name.to_s.capitalize.gsub(/(\w)-(\w)/) { [$1, $2.upcase].join } - if const_defined?(klass) - const_get(klass) - else - nil - end - end + if const_defined?(klass) + const_get(klass) + else + nil + end + end private def attr_child_names_for(name) @@ -313,12 +313,12 @@ klass = self.class.constantize_nodename(name) if klass value = klass.new(value) else - # try to force convert value - value = (value.is_a?(String) ? TextNode : Node).new(value) - value.nodename = name.to_s + # try to force convert value + value = (value.is_a?(String) ? TextNode : Node).new(value) + value.nodename = name.to_s end rescue => e raise ArgumentError, "failed to convert #{value.inspect} to node: #{e.message}" end unless value.respond_to?(:nodename) \ No newline at end of file