Class: Bamboo::Client::Http::Xml::Doc
- Inherits:
-
Object
- Object
- Bamboo::Client::Http::Xml::Doc
- Defined in:
- lib/bamboo-client/http/xml.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(doc) ⇒ Doc
constructor
A new instance of Doc.
- #object_for(selector, klass, *extra_args) ⇒ Object
- #objects_for(selector, klass, *extra_args) ⇒ Object
- #text_for(css) ⇒ Object
Constructor Details
#initialize(doc) ⇒ Doc
Returns a new instance of Doc.
12 13 14 15 16 |
# File 'lib/bamboo-client/http/xml.rb', line 12 def initialize(doc) @doc = doc puts doc.to_s if $DEBUG assert_no_error end |
Class Method Details
.from(str) ⇒ Object
8 9 10 |
# File 'lib/bamboo-client/http/xml.rb', line 8 def self.from(str) new(Nokogiri::XML(str)) end |
Instance Method Details
#object_for(selector, klass, *extra_args) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/bamboo-client/http/xml.rb', line 26 def object_for(selector, klass, *extra_args) node = @doc.css(selector).first node or raise Error, "no node matches selector #{selector.inspect}" klass.new node, *extra_args end |
#objects_for(selector, klass, *extra_args) ⇒ Object
22 23 24 |
# File 'lib/bamboo-client/http/xml.rb', line 22 def objects_for(selector, klass, *extra_args) @doc.css(selector).map { |e| klass.new(e, *extra_args) } end |
#text_for(css) ⇒ Object
18 19 20 |
# File 'lib/bamboo-client/http/xml.rb', line 18 def text_for(css) @doc.css(css).text end |