Class: Netscaler::ServiceGroup::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



3
4
5
# File 'lib/netscaler/servicegroup/response.rb', line 3

def initialize(raw_response)
  @info = raw_response[:return][:list][:item]
end

Instance Method Details

#nameObject



7
8
9
# File 'lib/netscaler/servicegroup/response.rb', line 7

def name
  @info[:servicegroupname]
end

#serversObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/netscaler/servicegroup/response.rb', line 19

def servers
  @parsed_servers ||= []
  return @parsed_servers if !@parsed_servers.empty? || @info[:servername].nil?

  if @info[:servername][:item].is_a?(String)
    @parsed_servers << ServerInfo.new(@info, nil)
  else
    @info[:servername][:item].each_with_index do |name, i|
      @parsed_servers << ServerInfo.new(@info, i)
    end
  end

  @parsed_servers
end

#stateObject



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

def state
  @info[:state]
end

#to_hashObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/netscaler/servicegroup/response.rb', line 34

def to_hash
  hash = { 
    :name => name,
    :state => state,
    :type => type,
  }

  if !servers.empty?
    hash[:servers] = servers.map {|s| s.to_hash}
  end

  hash
end

#typeObject



15
16
17
# File 'lib/netscaler/servicegroup/response.rb', line 15

def type
  @info[:servicetype]
end