Module: Recurly::XML::NokogiriAdapter
- Included in:
- Recurly::XML
- Defined in:
- lib/recurly/xml/nokogiri.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
30 31 32 |
# File 'lib/recurly/xml/nokogiri.rb', line 30 def [] xpath root.at_xpath xpath end |
#add_element(name, value = nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/recurly/xml/nokogiri.rb', line 8 def add_element name, value = nil root.add_child(node = ::Nokogiri::XML::Element.new(name, root)) node << value if value node end |
#each(element = root) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/recurly/xml/nokogiri.rb', line 19 def each element = root element.elements.each do |el| yield el each el, &Proc.new end end |
#each_element(xpath = nil) ⇒ Object
14 15 16 17 |
# File 'lib/recurly/xml/nokogiri.rb', line 14 def each_element xpath = nil elements = xpath.nil? ? root.children : root.xpath(xpath) elements.each { |el| yield el } end |
#initialize(xml) ⇒ Object
4 5 6 |
# File 'lib/recurly/xml/nokogiri.rb', line 4 def initialize xml @root = Nokogiri(xml).root end |
#name ⇒ Object
26 27 28 |
# File 'lib/recurly/xml/nokogiri.rb', line 26 def name root.name end |
#text(xpath = nil) ⇒ Object
34 35 36 |
# File 'lib/recurly/xml/nokogiri.rb', line 34 def text xpath = nil node = root.at_xpath(xpath) and node.text end |
#text=(text) ⇒ Object
38 39 40 |
# File 'lib/recurly/xml/nokogiri.rb', line 38 def text= text root.content = text end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/recurly/xml/nokogiri.rb', line 42 def to_s root.to_xml(:indent => 0).gsub(/$\n/, '') end |