ICanBoogie/CLDR master
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • CLDR
      • Plurals
      • Units

Classes

  • Sequence
  • Unit
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie\CLDR\Units;

use ICanBoogie\Accessor\AccessorTrait;
use ICanBoogie\CLDR\Units;

/**
 * Representation of a unit.
 *
 * @property-read string $name
 * @property-read string $long_name
 * @property-read string $short_name
 * @property-read string $narrow_name
 */
class Unit
{
    use AccessorTrait;

    /**
     * @var Units
     */
    private $units;

    /**
     * @var string
     */
    private $unit;

    /**
     * @return string
     */
    protected function get_name()
    {
        return $this->long_name;
    }

    /**
     * @return string
     */
    protected function get_long_name()
    {
        return $this->name_for(Units::LENGTH_LONG);
    }

    /**
     * @return string
     */
    protected function get_short_name()
    {
        return $this->name_for(Units::LENGTH_SHORT);
    }

    /**
     * @return string
     */
    protected function get_narrow_name()
    {
        return $this->name_for(Units::LENGTH_NARROW);
    }

    /**
     * @param Units $units
     * @param string $unit
     */
    public function __construct(Units $units, $unit)
    {
        $this->units = $units;
        $this->unit = $unit;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->unit;
    }

    /**
     * @param number|string $number
     * @param Unit|string $unit
     * @param string $length
     *
     * @return string
     */
    public function per_unit($number, $unit, $length = Units::DEFAULT_LENGTH)
    {
        return $this->units->format_combination($number, (string) $this, (string) $unit, $length);
    }

    /**
     * @param string $length One of `Units::LENGTH_*`.
     *
     * @return string
     */
    private function name_for($length)
    {
        return $this->units->name_for($this->unit, $length);
    }
}
ICanBoogie/CLDR master API documentation generated by ApiGen