Class: Vra::RequestParameter
- Inherits:
-
Object
- Object
- Vra::RequestParameter
- Defined in:
- lib/vra/request_parameters.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#key ⇒ Object
Returns the value of attribute key.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #format_value ⇒ Object
-
#initialize(key, type, value) ⇒ RequestParameter
constructor
A new instance of RequestParameter.
- #to_h ⇒ Object
- #to_vra ⇒ Object
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
#children ⇒ Object
Returns the value of attribute children.
108 109 110 |
# File 'lib/vra/request_parameters.rb', line 108 def children @children end |
#key ⇒ Object
Returns the value of attribute key.
108 109 110 |
# File 'lib/vra/request_parameters.rb', line 108 def key @key end |
#type ⇒ Object
Returns the value of attribute type.
108 109 110 |
# File 'lib/vra/request_parameters.rb', line 108 def type @type end |
#value ⇒ Object
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_value ⇒ Object
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_h ⇒ Object
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_vra ⇒ Object
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 |