Skip to content

Commit

Permalink
Add CardinalNumber::generate() for one-call numeral generation
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Feb 3, 2017
1 parent e0572bd commit ed79b68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ var_dump(morphos\Russian\Plurality::pluralize('дом', 10)); // домов
var_dump(morphos\Russian\Plurality::pluralize('гидродендрариум', 2)); // гидродендрариума
```

Generate russian cardinal numerals:

```php
var_dump(morphos\Russian\CardinalNumeral::generate(567)); // пятьсот шестьдесят семь
```

Pluralize english nouns:

```php
Expand Down Expand Up @@ -351,6 +357,7 @@ All number creation classes are similar and have two common methods:

- `string getForm($number, $case, $gender = NumeralCreation::MALE)` - Get one form of a number.
- `array getForms($number, $gender = NumeralCreation::MALE)` - Get all forms of a number.
- `string #generate($number, $gender = NumeralCreation::MALE)` - Generates a cardinal numeral for a number.

`$gender` is one of `morphos\NumeralCreation` constants: `MALE` or `FEMALE` or `NEUTER`.

Expand Down Expand Up @@ -399,6 +406,17 @@ var_dump($cardinal->getForms($number));
*/
```

Generate numeral of a number:

```php
use morphos\Russian\CardinalNumeral;

$number = 4351;

echo CardinalNumeral::generate($number);
// result: четыре тысячи триста пятьдесят один
```

## Cases (`Cases`)
Cases in russian language:

Expand Down
7 changes: 7 additions & 0 deletions src/Russian/CardinalNumeral.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,11 @@ public function getForm($number, $form, $gender = self::MALE) {
$forms = $this->getForms($number, $gender);
return $forms[$form];
}

static public function generate($number, $gender = self::MALE) {
static $card;
if ($card === null) $card = new self();

return $card->getForm($number, self::IMENIT, $gender);
}
}

0 comments on commit ed79b68

Please sign in to comment.