Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/karlomikus/recipe-utils
Utilities for extracting ingredient data from (mostly cocktail) recipes into structured objects.
https://github.com/karlomikus/recipe-utils
Last synced: about 2 months ago
JSON representation
Utilities for extracting ingredient data from (mostly cocktail) recipes into structured objects.
- Host: GitHub
- URL: https://github.com/karlomikus/recipe-utils
- Owner: karlomikus
- Created: 2023-08-07T14:23:20.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-04-24T13:11:36.000Z (8 months ago)
- Last Synced: 2024-04-24T16:42:23.150Z (8 months ago)
- Language: PHP
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Recipe Utilities
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/karlomikus/recipe-utils/code.yml)
![Packagist Version](https://img.shields.io/packagist/v/karlomikus/recipe-utils)
![GitHub License](https://img.shields.io/github/license/karlomikus/recipe-utils)Utilities for extracting ingredient data from (mostly cocktail) recipes into structured objects.
## Install
Install via composer
```bash
$ composer require karlomikus/recipe-utils
```## Parser usage
All parse methods return object of type `Kami\RecipeUtils\RecipeIngredient`.
```php
parseLine('30 ml Tequila reposado (preferebly Patron)');
var_dump($ingredient);
// Output:
// $ingredient->amount === '30'
// $ingredient->units === 'ml'
// $ingredient->name === 'Tequila reposado'
// $ingredient->comment === 'preferebly Patron'
// $ingredient->source === '30 ml Tequila reposado'// Parse a line and convert units if possible
$ingredient = $ingredientParser->parseLine('30 ml Tequila reposado (preferebly Patron)', Units::Oz);
var_dump($ingredient);
// Output:
// $ingredient->amount === 1.0
// $ingredient->units === 'oz'
// $ingredient->name === 'Tequila reposado'
// $ingredient->comment === 'preferebly Patron'
// $ingredient->source === '30 ml Tequila reposado'// Available via static call
$ingredient = Parser::line('30 ml Tequila reposado (preferebly Patron)');// Add custom units
$ingredientParser->setUnitParser(
new UnitParser([
'test' => ['lorem', 'ipsum']
])
);$ingredient = $ingredientParser->parseLine('15 lorem ingredient names');
// Output:
// $ingredient->units === 'test'
```## Unit converter usage
Simple unit conversion implemented with enums. Not made for accuracy. Handles mostly cocktail recipe units (ml, oz, cl, dash...). Can handle fractional display amounts (¾, 1 1/2..).
```php
amount === 45.0
// $ingredient->units === 'ml'
// $ingredient->name === 'Vodka'// Via specific units
$amountValue = AmountValue::fromString('1 1/2');
var_dump((new Oz($amountValue))->toMl()->getValue());
// Output:
// float: 45.0
```