예제 #1
0
 /**
  * @param string $rawQuery
  * @return Query
  * @throws QueryException
  * @throws \UnitConverter\Exception\NotSupportedUnitException
  */
 public function resolve(string $rawQuery) : Query
 {
     if (!preg_match('/(?<value>\\d+)\\s?(?<valueUnit>[a-z]{1,3})\\s{1,}to\\s{1,}(?:\\?)?\\s?(?<targetUnit>[a-z]{1,3})/', $rawQuery, $matches)) {
         throw new QueryException(sprintf('Not supported query: %s', $rawQuery));
     }
     return new Query(new Value($matches['value'], UnitFactory::build($matches['valueUnit'])), UnitFactory::build($matches['targetUnit']));
 }
 public function convertDataProvider()
 {
     return [[new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH), '3.93'], [new Value(10, UnitFactory::build(LengthUnit::INCH)), UnitFactory::build(LengthUnit::CENTIMETRE), '25.44']];
 }
 public function convertDataProvider()
 {
     return [[new Value(10, UnitFactory::build(WeightUnit::KILOGRAM)), UnitFactory::build(WeightUnit::TONNE), '0.01'], [new Value(1, UnitFactory::build(WeightUnit::TONNE)), UnitFactory::build(WeightUnit::POUNDS), '2204.62']];
 }
 public function availableQuery()
 {
     return [['10cm to ?in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10 cm to ?in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10 cm to ? in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10 cm  to ?in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10 cm to   ?in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10cm to in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))], ['10cm  to  in', new Query(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH))]];
 }