Skip to content

Commit 89fe10b

Browse files
committed
fix: ruby
1 parent 70b527c commit 89fe10b

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/SDK/Language/Ruby.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,38 @@ public function getParamExample(array $param): string
329329
* @return string
330330
* @var $data array
331331
*/
332-
protected function jsonToHash(array $data): string
332+
protected function jsonToHash(array $data, int $indent = 0): string
333333
{
334-
$output = '{';
334+
if (empty($data)) {
335+
return '{}';
336+
}
335337

338+
$output = "{\n";
339+
$indentStr = str_repeat(' ', $indent + 4);
340+
$keys = array_keys($data);
341+
336342
foreach ($data as $key => $node) {
337-
$value = (is_array($node)) ? $this->jsonToHash($node) : $node;
338-
$output .= '"' . $key . '" => ' . ((is_string($node)) ? '"' . $value . '"' : $value) . (($key !== array_key_last($data)) ? ', ' : '');
343+
if (is_array($node)) {
344+
$value = $this->jsonToHash($node, $indent + 1);
345+
} elseif (is_bool($node)) {
346+
$value = $node ? 'true' : 'false';
347+
} elseif (is_string($node)) {
348+
$value = '"' . $node . '"';
349+
} else {
350+
$value = $node;
351+
}
352+
353+
$output .= $indentStr . '"' . $key . '" => ' . $value;
354+
355+
// Add comma if not the last item
356+
if ($key !== end($keys)) {
357+
$output .= ',';
358+
}
359+
360+
$output .= "\n";
339361
}
340362

341-
$output .= '}';
363+
$output .= str_repeat(' ', $indent + 2) . '}';
342364

343365
return $output;
344366
}

0 commit comments

Comments
 (0)