* @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:----cXHkPyAbQUo+8mJeUFhc2HWwoXSk5+3J9BCCOh43vTJBA2jz3E7TZTFfOoKv8TvV+s4FsMpGkkxU1unV0XjjTNR8IoJ8fVOmMG6fmTx0Djv97o5HYVr2pffJzHOPL/BUSOR71361UYWO/E8BGG2ZZbksf2Rc4pWze6dhhxRVblySFg1fGzN0zsEPlwjLUOl6FKwteSKO9Vp7z0W3usBAP8FP7Er4chydNfq0PfM8mLggCqtEYExFe9a37cbobWKh3ho3jff0BjsK8JiWZWpy8SCPvAM5Zcb0PLbI0zRoZwWhIbeL6LvtTXqH2Wo1b/nKyu8IRO8DHaDQUz9pP/q9cgmHaTVCh9PZBV+mnz1WJ3EZPCq1HRKSz/CHi5Kxmnl/MM2/u8WBXx+raPOjAaapl9wtYn3Rbhx95zydlfotQcGJPofKwXS0Jj5ZAEEa29vcG8uRrJ3Wvl183ZODf3sooR7aVxkNeayJmbX6d+yD8KZl2/ZL4I7YZkxzR+lzZd90T28Y/QVFsEwsyDyyfNerHFvsGqWlsnnDrAeWlq2oryKQBdyXzLy9VKpkRLSk/4RqLrEgstvhaU64l72VgAExBQY/SCW4tN/qr0hqNiTt4er0rCP6IChh4nFW9GtAD/JxT3v5Blmp3DZIS9NIH6W7TD1tBL9HuTpb1h40hUd9FN8=----ATTACHMENT:----NzE3NDI2MjUwNDYyNjY4NCA0ODI5OTcwMTQ1MTgwOTMwIDU2NzM0MjYwNDkzOTg5ODM=