Class: Bamboo::Client::Http::Xml::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/bamboo-client/http/xml.rb

Class Method Summary collapse

Instance Method Summary collapse

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