class Vra::RequestParameter

Attributes

children[RW]
key[RW]
type[RW]
value[RW]

Public Class Methods

new(key, type, value) click to toggle source
# File lib/vra/request_parameters.rb, line 109
def initialize(key, type, value)
  @key   = key
  @type  = type
  @value = value
  @children = []
end

Public Instance Methods

add_child(child) click to toggle source
# File lib/vra/request_parameters.rb, line 116
def add_child(child)
  @children.push(child)
end
format_value() click to toggle source
# File lib/vra/request_parameters.rb, line 153
def format_value
  case @type
  when "integer"
    @value.to_i
  when "string"
    @value
  when "boolean"
    @value.to_s == "true"
  else
    @value
  end
end
to_h() click to toggle source
# File lib/vra/request_parameters.rb, line 120
def to_h
  hash = {}

  if @children.count > 0
    hash[@key] = {}

    @children.each do |c|
      hash[@key].merge!(c.to_h)
    end
  else
    hash[@key] = format_value
  end

  hash
end
to_vra() click to toggle source
# File lib/vra/request_parameters.rb, line 136
def to_vra
  hash = {}
  if @children.count > 0
    hash[@key] = {}

    hash[@key]["data"] = {}

    @children.each do |c|
      hash[@key]["data"].merge!(c.to_vra)
    end
  else
    hash[@key] = format_value
  end

  hash.each_with_object({}) { |(key, value), h| h[key.to_s] = value }
end