ingreedyfork 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.9
7
+ - 2.2.5
8
+ - 2.3.1
9
+ - ruby-head
10
+ - jruby-1.7.20
11
+ - jruby-9.0.5.0
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby-1.7.20
16
+ - rvm: jruby-9.0.5.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://www.rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Usage
2
+
3
+ ```ruby
4
+ result = Ingreedy.parse('1 lb. potatoes')
5
+ print result.amount
6
+ #=> 1.0
7
+ print result.unit
8
+ #=> :pound
9
+ print result.ingredient
10
+ #=> "potatoes"
11
+ ```
12
+
13
+ ### I18n and custom dictionaries
14
+
15
+ ```ruby
16
+ Ingreedy.dictionaries[:fr] = {
17
+ units: { dash: ['pincée'] },
18
+ numbers: { 'une' => 1 },
19
+ prepositions: ['de']
20
+ }
21
+
22
+ Ingreedy.locale = :fr # Also automatically follows I18n.locale if available
23
+
24
+ result = Ingreedy.parse('une pincée de sucre')
25
+ print result.amount
26
+ #=> 1.0
27
+ print result.unit
28
+ #=> :dash
29
+ print result.ingredient
30
+ #=> "sucre"
31
+ ```
32
+
33
+ ### Handling amounts
34
+
35
+ By default, Ingreedy will convert all amounts to a rational number:
36
+
37
+ ```ruby
38
+ result = Ingreedy.parse("1 1/2 cups flour")
39
+ print result.amount
40
+ #=> 3/2
41
+ ```
42
+
43
+ However, setting `Ingreedy.preverse_amounts = true`, will allow amounts
44
+ to be detected and returned as originally input:
45
+
46
+ ```ruby
47
+ Ingreedy.preserve_amounts = true
48
+
49
+ result = Ingreedy.parse("1 1/2 cups flour")
50
+ print result.amount
51
+ #=> 1 1/2
52
+ ```
53
+
54
+ [Live demo](http://hangryingreedytest.herokuapp.com/)
55
+
56
+ # Pieces of Flair
57
+ - [![Gem Version](https://badge.fury.io/rb/ingreedy.svg)](http://badge.fury.io/rb/ingreedy)
58
+ - [![Build Status](https://secure.travis-ci.org/iancanderson/ingreedy.svg?branch=master)](http://travis-ci.org/iancanderson/ingreedy)
59
+ - [![Code Climate](https://codeclimate.com/github/iancanderson/ingreedy.svg)](https://codeclimate.com/github/iancanderson/ingreedy)
60
+ - [![Coverage Status](https://coveralls.io/repos/iancanderson/ingreedy/badge.svg)](https://coveralls.io/r/iancanderson/ingreedy)
61
+
62
+ # Development
63
+
64
+ Run the tests:
65
+ ```
66
+ rspec spec
67
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task default: :spec
data/ingreedy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require File.expand_path("../lib/ingreedy/version", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ingreedyfork"
5
+ s.version = Ingreedy::VERSION
6
+ s.licenses = ["MIT"]
7
+ s.authors = ["Ian C. Anderson, support for Polish added by Mateusz Konieczny "]
8
+ s.email = ["matkoniecz@gmail.com"]
9
+
10
+ s.summary = "Recipe parser (fork of ingreedy)"
11
+ s.description = <<-MSG
12
+ Natural language recipe ingredient parser that supports numeric amount,
13
+ units, and ingredient
14
+ MSG
15
+ s.homepage = "http://github.com/matkoniecz/ingreedy-fork"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.require_path = "lib"
19
+
20
+ s.add_dependency "parslet", "~> 1.8.0", ">= 1.8.0"
21
+ s.add_dependency "unicode", "~> 0.4.4", ">= 0.4.4"
22
+
23
+ s.add_development_dependency "rake", "~> 0.9", ">= 0.9"
24
+ s.add_development_dependency "rspec", "~> 3.3.0", ">= 3.3.0"
25
+ s.add_development_dependency "coveralls", "~> 0.7.0", ">= 0.7.0"
26
+ s.add_development_dependency "pry", '~> 0'
27
+ end
@@ -0,0 +1,69 @@
1
+ require "parslet"
2
+
3
+ module Ingreedy
4
+ class AmountParser < Parslet::Parser
5
+ include CaseInsensitiveParser
6
+
7
+ rule(:whitespace) do
8
+ match("\s")
9
+ end
10
+
11
+ rule(:integer) do
12
+ match("[0-9]").repeat(1)
13
+ end
14
+
15
+ rule(:float) do
16
+ integer.maybe >>
17
+ float_delimiter >> integer
18
+ end
19
+
20
+ rule(:float_delimiter) do
21
+ str(",") | str(".")
22
+ end
23
+
24
+ rule(:fraction) do
25
+ compound_simple_fraction | compound_vulgar_fraction
26
+ end
27
+
28
+ rule(:compound_simple_fraction) do
29
+ (integer.as(:integer_amount) >> whitespace).maybe >>
30
+ simple_fraction.as(:fraction_amount)
31
+ end
32
+
33
+ rule(:simple_fraction) do
34
+ integer >> match("/") >> integer
35
+ end
36
+
37
+ rule(:compound_vulgar_fraction) do
38
+ (integer.as(:integer_amount) >> whitespace.maybe).maybe >>
39
+ vulgar_fraction.as(:fraction_amount)
40
+ end
41
+
42
+ rule(:vulgar_fraction) do
43
+ vulgar_fractions.map { |f| str(f) }.inject(:|)
44
+ end
45
+
46
+ rule(:word_digit) do
47
+ word_digits.map { |d| stri(d) }.inject(:|) || any
48
+ end
49
+
50
+ rule(:amount) do
51
+ fraction |
52
+ float.as(:float_amount) |
53
+ integer.as(:integer_amount) |
54
+ word_digit.as(:word_integer_amount) >> whitespace
55
+ end
56
+
57
+ root(:amount)
58
+
59
+ private
60
+
61
+ def word_digits
62
+ Ingreedy.dictionaries.current.numbers.keys
63
+ end
64
+
65
+ def vulgar_fractions
66
+ Ingreedy.dictionaries.current.vulgar_fractions.keys
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,12 @@
1
+ require 'unicode'
2
+
3
+ module Ingreedy
4
+ module CaseInsensitiveParser
5
+ def stri(str)
6
+ key_chars = str.split(//)
7
+ key_chars.
8
+ map! { |char| match["#{Unicode.upcase(char)}#{Unicode.downcase(char)}"] }.
9
+ reduce(:>>)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,147 @@
1
+ :units:
2
+ :cup:
3
+ - "cups"
4
+ - "cup"
5
+ - "c."
6
+ - "c"
7
+ :fluid_ounce:
8
+ - "fl. oz."
9
+ - "fl oz"
10
+ - "fluid ounce"
11
+ - "fluid ounces"
12
+ :gallon:
13
+ - "gal"
14
+ - "gal."
15
+ - "gallon"
16
+ - "gallons"
17
+ :ounce:
18
+ - "oz"
19
+ - "oz."
20
+ - "ounce"
21
+ - "ounces"
22
+ :pint:
23
+ - "pt"
24
+ - "pt."
25
+ - "pint"
26
+ - "pints"
27
+ :pound:
28
+ - "lb"
29
+ - "lb."
30
+ - "pound"
31
+ - "pounds"
32
+ :quart:
33
+ - "qt"
34
+ - "qt."
35
+ - "qts"
36
+ - "qts."
37
+ - "quart"
38
+ - "quarts"
39
+ :tablespoon:
40
+ - "tbsp."
41
+ - "tbsp"
42
+ - "T"
43
+ - "T."
44
+ - "tablespoon"
45
+ - "tablespoons"
46
+ - "tbs."
47
+ - "tbs"
48
+ :teaspoon:
49
+ - "tsp."
50
+ - "tsp"
51
+ - "t"
52
+ - "t."
53
+ - "teaspoon"
54
+ - "teaspoons"
55
+ :gram:
56
+ - "g"
57
+ - "g."
58
+ - "gr"
59
+ - "gr."
60
+ - "gram"
61
+ - "grams"
62
+ - "gramme"
63
+ - "grammes"
64
+ :kilogram:
65
+ - "kg"
66
+ - "kg."
67
+ - "kilogram"
68
+ - "kilograms"
69
+ - "kilogramme"
70
+ - "kilogrammes"
71
+ :liter:
72
+ - "l"
73
+ - "l."
74
+ - "liter"
75
+ - "liters"
76
+ - "litre"
77
+ - "litres"
78
+ :milligram:
79
+ - "mg"
80
+ - "mg."
81
+ - "milligram"
82
+ - "milligrams"
83
+ - "milligramme"
84
+ - "milligrammes"
85
+ :milliliter:
86
+ - "ml"
87
+ - "ml."
88
+ - "milliliter"
89
+ - "milliliters"
90
+ - "millilitre"
91
+ - "millilitres"
92
+ :pinch:
93
+ - "pinch"
94
+ - "pinches"
95
+ :dash:
96
+ - "dash"
97
+ - "dashes"
98
+ :touch:
99
+ - "touch"
100
+ - "touches"
101
+ :handful:
102
+ - "handful"
103
+ - "handfuls"
104
+ :stick:
105
+ - "stick"
106
+ - "sticks"
107
+ :clove:
108
+ - "cloves"
109
+ - "clove"
110
+ :can:
111
+ - "cans"
112
+ - "can"
113
+ :to_taste:
114
+ - "to taste"
115
+ :numbers:
116
+ a: 1
117
+ an: 1
118
+ zero: 0
119
+ one: 1
120
+ two: 2
121
+ three: 3
122
+ four: 4
123
+ five: 5
124
+ six: 6
125
+ seven: 7
126
+ eight: 8
127
+ nine: 9
128
+ ten: 10
129
+ eleven: 11
130
+ twelve: 12
131
+ thirteen: 13
132
+ fourteen: 14
133
+ fifteen: 15
134
+ sixteen: 16
135
+ seventeen: 17
136
+ eighteen: 18
137
+ nineteen: 19
138
+ twenty: 20
139
+ thirty: 30
140
+ forty: 40
141
+ fifty: 50
142
+ sixty: 60
143
+ seventy: 70
144
+ eighty: 80
145
+ ninety: 90
146
+ :prepositions:
147
+ - "of"
@@ -0,0 +1,230 @@
1
+ :units:
2
+ :cup:
3
+ - "szklanka"
4
+ - "szklanek"
5
+ - "szklanki"
6
+ - "szkl"
7
+ - "szkl."
8
+ :spoon:
9
+ - "płaska łyżka"
10
+ - "płaskich łyżek"
11
+ - "płaskie łyżki"
12
+ - "płaskiej łyżki"
13
+ - "łyżka"
14
+ - "łyżek"
15
+ - "łyżki"
16
+ :teaspoon:
17
+ - "płaska łyżeczka"
18
+ - "płaskich łyżeczek"
19
+ - "płaskie łyżeczki"
20
+ - "płaskiej łyżeczki"
21
+ - "łyżeczka"
22
+ - "łyżeczek"
23
+ - "łyżeczki"
24
+ :rounded_tablespoon:
25
+ - "czubata łyżka"
26
+ - "czubatych łyżek"
27
+ - "czubate łyżki"
28
+ - "czubatej łyżki"
29
+ :rounded_teaspoon:
30
+ - "czubata łyżeczka"
31
+ - "czubatych łyżeczek"
32
+ - "czubate łyżeczki"
33
+ - "czubatej łyżeczki"
34
+ :heaped_tablespoon:
35
+ - "kopiasta łyżka"
36
+ - "kopiastych łyżek"
37
+ - "kopiaste łyżki"
38
+ - "kopiastej łyżki"
39
+ :heaped_teaspoon:
40
+ - "kopiasta łyżeczka"
41
+ - "kopiastych łyżeczek"
42
+ - "kopiaste łyżeczki"
43
+ - "kopiastej łyżeczki"
44
+ :gram:
45
+ - "g"
46
+ - "g."
47
+ - "gr"
48
+ - "gr."
49
+ - "gram"
50
+ - "gramy"
51
+ - "grama"
52
+ :dekagram:
53
+ - "dag"
54
+ - "dag."
55
+ - "deko"
56
+ - "dekagram"
57
+ - "dkg"
58
+ - "dkg."
59
+ :kilogram:
60
+ - "kg"
61
+ - "kg."
62
+ - "kilo"
63
+ - "kilogram"
64
+ - "kilograma"
65
+ - "kilogramy"
66
+ - "kilogramu"
67
+ - "kilogramów"
68
+ :liter:
69
+ - "l"
70
+ - "l."
71
+ - "litr"
72
+ - "litry"
73
+ - "litra"
74
+ :milligram:
75
+ - "mg"
76
+ - "mg."
77
+ - "milligram"
78
+ - "milligrama"
79
+ - "milligramy"
80
+ - "milligramu"
81
+ - "milligramów"
82
+ - "milligramow"
83
+ :milliliter:
84
+ - "ml"
85
+ - "ml."
86
+ - "mililitr"
87
+ - "mililitra"
88
+ - "mililitry"
89
+ - "mililitru"
90
+ - "mililitrów"
91
+ - "mililitrow"
92
+ :pinch:
93
+ - "szczypta"
94
+ - "szczypty"
95
+ - "szczypt"
96
+ :handful:
97
+ - "garść"
98
+ - "garście"
99
+ - "garści"
100
+ :clove:
101
+ - "ząbek"
102
+ - "ząbka"
103
+ - "ząbku"
104
+ - "ząbki"
105
+ - "ząbków"
106
+ :cube:
107
+ - "kostka"
108
+ - "kostek"
109
+ - "kostek"
110
+ :to_taste:
111
+ - "do smaku"
112
+ :for_decoration:
113
+ - "do ozdobienia"
114
+ :part:
115
+ - "kawałek"
116
+ - "kawałka"
117
+ - "kawałki"
118
+ - "fragment"
119
+ - "fragmenty"
120
+ - "fragmencik"
121
+ - "troszke"
122
+ - "troszkę"
123
+ :piece:
124
+ - "sztuka"
125
+ - "sztuk"
126
+ - "sztuke"
127
+ - "sztuki"
128
+ - "szt"
129
+ - "szt."
130
+ - "x"
131
+ - "butelki"
132
+ - "butelek"
133
+ - "butelke"
134
+ - "butelka"
135
+ - "opakowań"
136
+ - "opakowanie"
137
+ - "opakowania"
138
+ - "paczka"
139
+ - "paczke"
140
+ - "paczki"
141
+ - "pętko"
142
+ - "pętka"
143
+ - "pętek"
144
+ - "puszka"
145
+ - "puszke"
146
+ - "puszki"
147
+ :small_bundle:
148
+ - "pęczek"
149
+ - "pęczki"
150
+ - "pęczków"
151
+ - "pęczka"
152
+ :seed:
153
+ - "ziarno"
154
+ - "ziarna"
155
+ - "ziaren"
156
+ - "ziarenko"
157
+ - "ziarenka"
158
+ - "ziarenek"
159
+ :portion:
160
+ - "porcja"
161
+ - "porcje"
162
+ - "porcji"
163
+ :stem:
164
+ - "łodyga"
165
+ - "łodyg"
166
+ - "łodygi"
167
+ :metre:
168
+ - "m"
169
+ - "metr"
170
+ - "metra"
171
+ - "metry"
172
+ - "metrów"
173
+ :centimetre:
174
+ - "cm"
175
+ - "centymetr"
176
+ - "centymetra"
177
+ - "centymetry"
178
+ - "centymetrów"
179
+ :slice:
180
+ - "kromka"
181
+ - "kromek"
182
+ - "kromki"
183
+ :tea_bag:
184
+ - "szczur"
185
+ - "szczury"
186
+ - "szczura"
187
+ :numbers:
188
+ cwiartka: 0.25
189
+ ćwiartka: 0.25
190
+
191
+ pół: 0.5
192
+ połowa: 0.5
193
+
194
+ jedna: 1
195
+ jeden: 1
196
+ jedno: 1
197
+
198
+ półtora: 1.5
199
+
200
+ dwie: 2
201
+ dwa: 2
202
+ dwoje: 2
203
+
204
+ trzy: 3
205
+ troje: 3
206
+
207
+ cztery: 4
208
+ czworo: 4
209
+
210
+ kilka: 5
211
+ pięć: 5
212
+ piątka: 5
213
+
214
+ sześć: 6
215
+ sześcioro: 6
216
+ szóstka: 6
217
+
218
+ siedem: 7
219
+ siedmiu: 7
220
+
221
+ osiem: 8
222
+ ośmiu: 8
223
+
224
+ dziewięć: 9
225
+ dziewięciu: 9
226
+
227
+ dziesięć: 10
228
+ dziesięciu: 10
229
+
230
+ :prepositions: