class REXML::Nodes

Public Instance Methods

+(other) click to toggle source
Calls superclass method
# File source/zenml/utility.rb, line 171
def +(other)
  return REXML::Nodes.new(super(other))
end
<<(object) click to toggle source
# File source/zenml/utility.rb, line 160
def <<(object)
  if object.is_a?(REXML::Nodes)
    object.each do |child|
      old_push(child)
    end
  else
    old_push(object)
  end
  return self
end
Also aliased as: old_push
old_push(object)
Alias for: <<
trim_indents() click to toggle source
# File source/zenml/utility.rb, line 175
def trim_indents
  texts = []
  if self.last.is_a?(REXML::Text)
    self.last.value = self.last.value.rstrip
  end
  self.each do |child|
    case child
    when REXML::Text
      texts << child
    when REXML::Element
      texts.concat(child.get_texts_recursive)
    end
  end
  indent_length = Float::INFINITY
  texts.each do |text|
    text.value.scan(/\n(\x20+)/) do |match|
      indent_length = [match[0].length, indent_length].min
    end
  end
  texts.each do |text|
    text.value = text.value.gsub(/\n(\x20+)/){"\n" + " " * ($1.length - indent_length)}
  end
  if self.first.is_a?(REXML::Text)
    self.first.value = self.first.value.lstrip
  end
end