Class: HostConnect::AbstractResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/hostconnect/response.rb

Overview

Abstract response class. Each subclass takes the XML responses and turns them into a basic datastructure, with each element available as an attribute.

Instance Method Summary collapse

Instance Method Details

#[](num) ⇒ Object

Act like an array



21
22
23
# File 'lib/hostconnect/response.rb', line 21

def [](num)
  elements[num]
end

#eachObject

Yields each element



6
7
8
# File 'lib/hostconnect/response.rb', line 6

def each
  elements.each { |e| yield e }
end

#elementsObject

Exposes the element-array of responses which consists of multiple elements. Raises an error if used on non-collection responses (Ping etc).



27
28
29
# File 'lib/hostconnect/response.rb', line 27

def elements
  (@elements.blank?) ? raise(ArgumentError, "Not a collection") : @elements
end

#firstObject

Returns the first element



11
12
13
# File 'lib/hostconnect/response.rb', line 11

def first
  elements.first
end

#lastObject

Returns the last element



16
17
18
# File 'lib/hostconnect/response.rb', line 16

def last
  elements.last
end