Class: Vra::RequestParameter

Inherits:
Object
  • Object
show all
Defined in:
lib/vra/request_parameters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, type, value) ⇒ RequestParameter

Returns a new instance of RequestParameter.



109
110
111
112
113
114
# File 'lib/vra/request_parameters.rb', line 109

def initialize(key, type, value)
  @key   = key
  @type  = type
  @value = value
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



108
109
110
# File 'lib/vra/request_parameters.rb', line 108

def children
  @children
end

#keyObject

Returns the value of attribute key.



108
109
110
# File 'lib/vra/request_parameters.rb', line 108

def key
  @key
end

#typeObject

Returns the value of attribute type.



108
109
110
# File 'lib/vra/request_parameters.rb', line 108

def type
  @type
end

#valueObject

Returns the value of attribute value.



108
109
110
# File 'lib/vra/request_parameters.rb', line 108

def value
  @value
end

Instance Method Details

#add_child(child) ⇒ Object



116
117
118
# File 'lib/vra/request_parameters.rb', line 116

def add_child(child)
  @children.push(child)
end

#format_valueObject



154
155
156
157
158
159
160
161
162
163
# File 'lib/vra/request_parameters.rb', line 154

def format_value
  case @type
  when "integer"
    @value.to_i
  when "string"
    @value
  else
    @value
  end
end

#to_hObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# 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_vraObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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
end