https://github.com/matkoniecz/ingreeedyfork
fork of https://github.com/iancanderson/ingreedy (:pl support, minor bugfixes)
https://github.com/matkoniecz/ingreeedyfork
Last synced: 6 months ago
JSON representation
fork of https://github.com/iancanderson/ingreedy (:pl support, minor bugfixes)
- Host: GitHub
- URL: https://github.com/matkoniecz/ingreeedyfork
- Owner: matkoniecz
- Created: 2017-07-07T08:05:00.000Z (over 8 years ago)
- Default Branch: fork
- Last Pushed: 2018-02-15T14:56:49.000Z (over 7 years ago)
- Last Synced: 2025-02-14T07:31:54.078Z (8 months ago)
- Language: Ruby
- Size: 110 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Usage
```ruby
result = Ingreedy.parse('1 lb. potatoes')
print result.amount
#=> 1.0
print result.unit
#=> :pound
print result.ingredient
#=> "potatoes"
```### I18n and custom dictionaries
```ruby
Ingreedy.dictionaries[:fr] = {
units: { dash: ['pincée'] },
numbers: { 'une' => 1 },
prepositions: ['de']
}Ingreedy.locale = :fr # Also automatically follows I18n.locale if available
result = Ingreedy.parse('une pincée de sucre')
print result.amount
#=> 1.0
print result.unit
#=> :dash
print result.ingredient
#=> "sucre"
```### Handling amounts
By default, Ingreedy will convert all amounts to a rational number:
```ruby
result = Ingreedy.parse("1 1/2 cups flour")
print result.amount
#=> 3/2
```However, setting `Ingreedy.preverse_amounts = true`, will allow amounts
to be detected and returned as originally input:```ruby
Ingreedy.preserve_amounts = trueresult = Ingreedy.parse("1 1/2 cups flour")
print result.amount
#=> 1 1/2
```[Live demo](http://hangryingreedytest.herokuapp.com/)
# Pieces of Flair
- [](http://badge.fury.io/rb/ingreedy)
- [](http://travis-ci.org/iancanderson/ingreedy)
- [](https://codeclimate.com/github/iancanderson/ingreedy)
- [](https://coveralls.io/r/iancanderson/ingreedy)# Development
Run the tests:
```
rspec spec
```