vbpupil/measurement-converter

A simple but effective measurement converter which allows you to quickly create measurement objects that can be easily converted into other measurement formats, for example converting an Imperial measurement into Metric.

1.3.1 2018-04-04 08:46 UTC

This package is auto-updated.

Last update: 2024-11-07 00:17:03 UTC


README

PHP 5.6 PHP 7 Build Status Code Climate License: MIT

Measurement Converter

A simple but effective measurement converter which allows you to quickly create measurement objects that can be easily converted into other measurement formats, for example converting an Imperial measurement into Metric.

Currently this package supports the following:

  1. Metric Linears
  2. Imperial Linears
  3. Metric Cubic
  4. Imperial Cubic
  5. Weights Conversion
    • Tonne
    • US Ton
    • Imperial Ton

By creating a linear measurement unit object you immediately inherit the values of that conversion to your units counterparts. For example, by creating a 1 Inch Object you also have access to the Feet, Yard & Mile measurements off the bat

Supported Units

Usage Examples

Metric Example

1. create a 50 foot object

$feet= LinearUnitBuilder::build(new FloatType(18), new StringType('ft'));
dump($feet->getHumanReadableLong());

2. convert that into millimeters

$converter = new LinearUnitsConverter($feet, new StringType('mm'));

3. get the new millimeters object

$mm = $converter->get();
dump($mm->getHumanReadableLong());

4. convert millemeters into inches & get the inches object

$converter = new LinearUnitsConverter($mm, new StringType('in'));
$inch = $converter->get();
dump($inch->getHumanReadableLong());

Cubic Example

1. create a width, depth & height object and pass these into the cubic constructor

$width = LinearUnitBuilder::build(new FloatType(18), new StringType('m'));
$depth = LinearUnitBuilder::build(new FloatType(42), new StringType('m'));
$height = LinearUnitBuilder::build(new FloatType(3), new StringType('cm'));

$cubic = new CubicUnit($width, $depth, $height);
dump($cubic->getValue(new StringType('mm')));

Weight Example

1. to convert the cubic measurement into a weight simply pass in the SUPPORTED matrial name & cubic object

$tonnage = new WeightTonnageDensityConverter('soil', $cubic);

dump($cubic);
dump($tonnage->getValue());

2. you can also supply your own density measurement, which will be added to the density array as custom

$tonnage = new WeightTonnageDensityConverter(1.2, $cubic);

dump($cubic);
dump($tonnage->getValue());

Simple Conversion Example

1. start by creating a simple 20 foot Imperial LinearUnit object

$length = LinearUnitBuilder::build(new FloatType(20), new StringType('ft'));

2. then convert this into a cm Metric LinearUnit object

$length = LinearUnitBuilder::build(
                    new FloatType((new Conversion($l))->into(
                        new StringType('cm')
                    )),
                    new StringType(
                        'cm'
                    ));

Supported Materials & Densities