class REXML::Element

Public Class Methods

build(name, &block) click to toggle source
# File source/zenml/utility.rb, line 130
def self.build(name, &block)
  element = REXML::Element.new(name)
  block.call(element)
  return element
end

Public Instance Methods

[](key) click to toggle source
# File source/zenml/utility.rb, line 75
def [](key)
  if key.is_a?(String)
    return attribute(key).to_s
  else
    return old_get_index(key)
  end
end
Also aliased as: old_get_index
[]=(key, *values) click to toggle source
# File source/zenml/utility.rb, line 83
def []=(key, *values)
  if key.is_a?(String)
    return add_attribute(key, values.first)
  else
    return old_set_index(key, *values)
  end
end
Also aliased as: old_set_index
each_xpath(*args, &block) click to toggle source
# File source/zenml/utility.rb, line 91
def each_xpath(*args, &block)
  if block
    REXML::XPath.each(self, *args) do |element|
      block.call(element)
    end
  else
    enumerator = Enumerator.new do |yielder|
      REXML::XPath.each(self, *args) do |element|
        yielder << element
      end
    end
    return enumerator
  end
end
get_texts_recursive() click to toggle source
# File source/zenml/utility.rb, line 106
def get_texts_recursive
  texts = []
  self.children.each do |child|
    case child
    when REXML::Text
      texts << child
    when REXML::Element
      texts.concat(child.get_texts_recursive)
    end
  end
  return texts
end
inner_text(compress = false) click to toggle source
# File source/zenml/utility.rb, line 119
def inner_text(compress = false)
  text = REXML::XPath.match(self, ".//text()").map{|s| s.value}.join("")
  if compress
    text.gsub!(/\r/, "")
    text.gsub!(/\n\s*/, " ")
    text.gsub!(/\s+/, " ")
    text.strip!
  end
  return text
end
old_get_index(key)
Alias for: []
old_set_index(key, *values)
Alias for: []=