Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new unit: miles per imperial gallon(mpig) #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class ToLitrePer100Kilometres extends AbstractFormula
{
const MAGIC_NUMBER = 100;

const FORMULA_STRING = 'L/100km = 100 / km/l';

const FORMULA_TEMPLATE = '%s L/100km = 100 / %skm/l';
Expand All @@ -34,7 +36,7 @@ class ToLitrePer100Kilometres extends AbstractFormula
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->div(100, $value);
$addResult = $this->calculator->div(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\KilometrePerLitre;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert Kilometre Per Litre values to Miles Per Gallon.
*
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToMilesPerGallonImperial extends AbstractFormula
{

const MAGIC_NUMBER = 2.82481;

const FORMULA_STRING = 'mpg(Imperial) = 2.82481 * km/l';

const FORMULA_TEMPLATE = '%s mpg(Imperial) = 2.82481 * %skm/l';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->mul(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToMilesPerGallon extends AbstractFormula
class ToMilesPerGallonUS extends AbstractFormula
{

const MAGIC_NUMBER = 2.35215;

const FORMULA_STRING = 'mpg = 2.35215 * km/l';
const FORMULA_STRING = 'mpg(US) = 2.35215 * km/l';

const FORMULA_TEMPLATE = '%s mpg = 2.35215 * %skm/l';
const FORMULA_TEMPLATE = '%s mpg(US) = 2.35215 * %skm/l';

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class ToKilometrePerLitre extends AbstractFormula
{
const MAGIC_NUMBER = 100;

const FORMULA_STRING = 'km/l = 100 / L/100km';

const FORMULA_TEMPLATE = '%s km/l = 100 / %sL/100km';
Expand All @@ -34,7 +36,7 @@ class ToKilometrePerLitre extends AbstractFormula
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->div(100, $value);
$addResult = $this->calculator->div(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\LitrePer100Kilometres;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert Miles Per Gallon Per 100 Kilometres values to Miles Per Gallon.
*
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToMilesPerGallonImperial extends AbstractFormula
{

const MAGIC_NUMBER = 282.481;

const FORMULA_STRING = 'mpg(Imperial) = 282.481 / L/100km';

const FORMULA_TEMPLATE = '%s mpg(Imperial) = 282.481 / %sL/100km';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->div(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToMilesPerGallon extends AbstractFormula
class ToMilesPerGallonUS extends AbstractFormula
{

const MAGIC_NUMBER = 235.215;

const FORMULA_STRING = 'mpg = 235.215 / L/100km';
const FORMULA_STRING = 'mpg(US) = 235.215 / L/100km';

const FORMULA_TEMPLATE = '%s mpg = 235.215 / %sL/100km';
const FORMULA_TEMPLATE = '%s mpg(US) = 235.215 / %sL/100km';

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallonImperial;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert Miles Per Gallon values to Kilometre Per Litre.
*
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToKilometrePerLitre extends AbstractFormula
{

const MAGIC_NUMBER = 0.354006;

const FORMULA_STRING = 'km/l = 0.354006 * mpg(imp)';

const FORMULA_TEMPLATE = '%s km/l = 0.354006 * %smpg(imp)';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->mul(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallonImperial;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert Miles Per Gallon values to Litre Per 100 Kilometres.
*
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToLitrePer100Kilometres extends AbstractFormula
{

const MAGIC_NUMBER = 282.481;

const FORMULA_STRING = 'L/100km = 282.481 / mpg(imp)';

const FORMULA_TEMPLATE = '%s L/100km = 282.481 / %smpg(imp)';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->div(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallonImperial;

use UnitConverter\Calculator\Formula\AbstractFormula;

/**
* Formula to convert Kilometre Per Litre values to Miles Per Gallon.
*
* @version 1.0.0
* @author Maksim Martianov <7222812+maksimru@users.noreply.github.com>
*/
class ToMilesPerGallonUS extends AbstractFormula
{

const MAGIC_NUMBER = 0.832674;

const FORMULA_STRING = 'mpg(Imperial) = 0.832674 * mpg(US)';

const FORMULA_TEMPLATE = '%s mpg(Imperial) = 0.832674 * %smpg(US)';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->mul(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallon;
namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallonUS;

use UnitConverter\Calculator\Formula\AbstractFormula;

Expand All @@ -27,9 +27,9 @@ class ToKilometrePerLitre extends AbstractFormula

const MAGIC_NUMBER = 0.425144;

const FORMULA_STRING = 'km/l = 0.425144 * mpg';
const FORMULA_STRING = 'km/l = 0.425144 * mpg(US)';

const FORMULA_TEMPLATE = '%s km/l = 0.425144 * %smpg';
const FORMULA_TEMPLATE = '%s km/l = 0.425144 * %smpg(US)';

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallon;
namespace UnitConverter\Calculator\Formula\FuelEconomy\MilesPerGallonUS;

use UnitConverter\Calculator\Formula\AbstractFormula;

Expand All @@ -24,17 +24,20 @@
*/
class ToLitrePer100Kilometres extends AbstractFormula
{
const FORMULA_STRING = 'L/100km = 235.215 / mpg';

const FORMULA_TEMPLATE = '%s L/100km = 235.215 / %smpg';
const MAGIC_NUMBER = 235.215;

const FORMULA_STRING = 'L/100km = 235.215 / mpg(US)';

const FORMULA_TEMPLATE = '%s L/100km = 235.215 / %smpg(US)';

/**
* {@inheritDoc}
*/
public function describe($value, $fromUnits, $toUnits, int $precision = null)
{
// XXX: this formula assumes all calculators can accept strings, as it's the safest type.
$addResult = $this->calculator->div(235.215, $value);
$addResult = $this->calculator->div(self::MAGIC_NUMBER, $value);
$result = $this->calculator->round($addResult, $precision);

$this->plugVariables($result, $value);
Expand Down
Loading