2017 © Pedro Peláez
 

library temperature

Simple library to handle temperature scales

image

ayeo/temperature

Simple library to handle temperature scales

  • Friday, December 19, 2014
  • by ayeo
  • Repository
  • 2 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status Scrutinizer Code Quality Software License Packagist Version Code Coverage, (*1)

Temperature

Simple library to handle temperature scales. Features: * Display formatted tempteratue (e.g 100 °C) * Simple convert beetwen different scales, (*2)

Supported temperature scales

  • Celsius (C)
  • Kelvin (K)
  • Farenheit (F)
  • Rankine (R)
  • Reaumur (Re)

Install using Composer

require: {
    "ayeo/temperature": "~0.1"
}

Basic usage

use Temperature\Factory\DefaultFactory as TemperatureFactory;

$factory = new TemperatureFactory();
$temperature = $factory->build(63, 'F');

$temperature; //63 °F
$temperature->convert('C'); //17.2222222222 °C
$temperature->convert('C')->setPrecision(2); //17.22 °C

Auto conversion

You can set Factory to autoconvert temperatures to given scale, (*3)

use Temperature\Factory\DefaultFactory as TemperatureFactory;

$factory = new TemperatureFactory;
$factory->setAutoconvertTo('C');
$factory->getFormatter()->setPrecision(2);

$factory->build(100, 'F'); //37.78 °C

Custom formatter

As default formatter is build by your locale settings. You can adjust it to your needs., (*4)

use Temperature\Formatter\StandardFormatter;

$formatter = new StandardFormatter();
$formatter->setDecimalSeperator(",");
$formatter->setPrecision(2);
$formatter->setShowSymbolMode(false);

$factory->setFormatter($formatter);

$factory->build(10.50, 'C'); //10,50
$factory->build(100, 'K'); //100

You can write your own Formatter. I must implemetnts FormatterInterface., (*5)

Custom temperature scale

Assume you need new temperature scale. For purpose of this example let say C2 = 2 * Celsius, (*6)

use \Temperature\Scales\Scale\AbstractScale;

class C2Scale extends AbstractScale
{
    const SYMBOL = "C2";

    /**
     * @return float
     */
    function getValueInCelsius()
    {
        return $this->value / 2;
    }

    /**
     * @param $celsius
     */
    function setValueInCelsius($celsius)
    {
        $this->value = $celsius * 2;
    }
}

$factory->getSupportedScales()->addSupportedType('C2', 'C2Scale');
$factory->build(100, 'C')->convert('C2'); //200 C2
$factory->build(50, 'K')->convert('C2'); //-446 C2

License

The MIT License (MIT). Please see the license file for more information., (*7)

The Versions

19/12 2014

dev-master

9999999-dev https://github.com/ayeo/temperature

Simple library to handle temperature scales

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

19/12 2014

0.1.1

0.1.1.0 https://github.com/ayeo/temperature

Simple library to handle temperature scales

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

19/12 2014

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1 https://github.com/ayeo/temperature

Simple library to handle temperature scales

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires