Module: Recurly::XML::REXMLAdapter
- Included in:
- Recurly::XML
- Defined in:
- lib/recurly/xml/rexml.rb
Instance Method Summary collapse
- #[](xpath) ⇒ Object
- #add_element(name, value = nil) ⇒ Object
- #each(element = root) ⇒ Object
- #each_element(xpath = nil) ⇒ Object
- #initialize(xml) ⇒ Object
- #name ⇒ Object
- #text(xpath = nil) ⇒ Object
- #text=(text) ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#[](xpath) ⇒ Object
31 32 33 |
# File 'lib/recurly/xml/rexml.rb', line 31 def [] xpath root.get_elements(xpath).first end |
#add_element(name, value = nil) ⇒ Object
10 11 12 13 14 |
# File 'lib/recurly/xml/rexml.rb', line 10 def add_element name, value = nil node = root.add_element name node.text = value if value node end |
#each(element = root) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/recurly/xml/rexml.rb', line 20 def each element = root element.each_element do |el| yield el each el, &Proc.new end end |
#each_element(xpath = nil) ⇒ Object
16 17 18 |
# File 'lib/recurly/xml/rexml.rb', line 16 def each_element xpath = nil root.each_element(xpath) { |el| yield el } end |
#initialize(xml) ⇒ Object
6 7 8 |
# File 'lib/recurly/xml/rexml.rb', line 6 def initialize xml @root = ::REXML::Document.new(xml).root end |
#name ⇒ Object
27 28 29 |
# File 'lib/recurly/xml/rexml.rb', line 27 def name root.name end |
#text(xpath = nil) ⇒ Object
35 36 37 |
# File 'lib/recurly/xml/rexml.rb', line 35 def text xpath = nil text = root.get_text(xpath) and text.to_s end |
#text=(text) ⇒ Object
39 40 41 |
# File 'lib/recurly/xml/rexml.rb', line 39 def text= text root.text = text end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/recurly/xml/rexml.rb', line 43 def to_s root.to_s end |