* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Ruby extends CodeGeneratorAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.rb'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\Ruby($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $code = 'class ' . $name . "\n"; if (!empty($extends)) { $code.= $this->indent . 'extend ' . $extends . "\n"; } $attr = []; $items = []; foreach ($properties as $name => $property) { /** @var Code\Property $property */ $attr[] = ':' . $name; $items[] = $name; } if (!empty($attr)) { $code.= $this->indent . 'attr_accessor ' . implode(', ', $attr) . "\n"; } $code.= "\n"; $code.= $this->indent . 'def initialize(' . implode(', ', $items) . ')' . "\n"; foreach ($items as $item) { $code.= $this->indent . $this->indent . '@' . $item . ' = ' . $item . "\n"; } $code.= $this->indent . 'end' . "\n"; $code.= 'end' . "\n"; return $code; } protected function writeReference(string $name, string $type, ReferenceType $origin): string { $code = 'class ' . $name . "\n"; $code.= $this->indent . 'extend ' . $type . "\n"; $code.= 'end' . "\n"; return $code; } protected function writeHeader(TypeAbstract $origin): string { $code = ''; if (!empty($this->namespace)) { $code.= 'module ' . $this->namespace . "\n"; $code.= "\n"; } $comment = $origin->getDescription(); if (!empty($comment)) { $code.= '# ' . $comment . "\n"; } return $code; } protected function writeFooter(TypeAbstract $origin): string { $code = ''; if (!empty($this->namespace)) { $code.= 'end' . "\n"; } return $code; } } __halt_compiler();----SIGNATURE:----SH+vGE4IQNDgg3ZYWzwLegMyl76+1lWccLNdaEOjK77Qs3JNKTtZ5pCAqESRyz9AbAJfptGhm9Hq6d3LAVM2oOuq8fQjWXQCzAgB3tCilLu9svMYsu4BJyYvEkQftF8XOhza4f83B6dmaqJ5Fwb//lrpul4fIZ+BTEvyEOLqmi/0klTcfZHWaYi++cNuAO4rzoO+0QKKXKsVQclrQU1s0FT1aWDyUEazhD8csMz5i7DkcSJRV/1xVdLlqf9GitrHRuGFq4kg8nrwvCT68GyGymoO1XGiwuXnRVF03l50Lfm8S9LZnnElcZxJe1KSgEi0oM2eltaKw+j3GSEXsWg0JPWRRUDXhTStVsbA/gJI3MaFFo5REw+S265gqigWkXyDkEoTgZ3J4+iFTIuAPo36/Lm1nyyqC5dBGpfbWv144xj7mLXnEcPFdl2hXcgF5br62BdWhXYtf6OnPnarYWDII9lT7TuGUVIjXh+JlQ20wjoWxDYhIg77wunZ+EFQLbVukBlH7BjLRMbrZiesYjsh0OqBYV8+6TgoO3BspCKyMCTpXcUjyRJ6aHY/OaO9SSAUjoJ46QSRUxhrg9u8txBVp6SrKEfKIUxExnu+6Mnn6NhkbcoPyAyGl037OpBO7KN+g8Y+vxleOYgzqrKgO5xhUMMg6Znl5RiSda67zuOX1Zw=----ATTACHMENT:----NTA3NjEyNDkyOTM1Nzg0OSAyOTIzOTg0Njk0Mjc1NDkxIDQ2MjA0NDUxNzQ0MTc2OTc=