food_ingredient_parser 1.0.0.pre.4 → 1.0.0.pre.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/food_ingredient_parser.gemspec +1 -1
- data/lib/food_ingredient_parser/to_html.rb +11 -2
- data/lib/food_ingredient_parser/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8725e4ed3763020de6b46cad6709ce05aca0b77f
|
4
|
+
data.tar.gz: fedb82af99346e8db38a3beaca5914ab44be197a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 114feb403f87140f2eccc21860c9a75aff4cff3583f3046f9815299f90dc6374c73b3b9ee60d682c3a9f91b2803ab3fc6c934f3255716986a494fbb51c9e5564
|
7
|
+
data.tar.gz: 8f94825d627ab8068fb3dfd6c20f61a20fc8612f06ec6a760d33e46def103ca11497e364d9e3a7c4720647794e644a7253ba6e226d984801a55e089a5961b753
|
data/README.md
CHANGED
@@ -124,11 +124,19 @@ puts parsed.to_html
|
|
124
124
|
```
|
125
125
|
|
126
126
|
```html
|
127
|
-
<span class='
|
128
|
-
<span class='name'>
|
129
|
-
<span class='
|
127
|
+
<span class='depth0'>
|
128
|
+
<span class='name'>Saus</span> (
|
129
|
+
<span class='contains depth1'>
|
130
|
+
<span class='amount'>10%</span> <span class='name'>tomaat</span><span class='mark'>*</span>,
|
131
|
+
<span class='name'>zout</span>
|
132
|
+
</span>)
|
133
|
+
</span>.
|
134
|
+
<span class='note'>* = bio</span>
|
130
135
|
```
|
131
136
|
|
137
|
+
For an example of an interactive editor, see [examples/editor.rb](examples/editor.rb).
|
138
|
+
|
139
|
+

|
132
140
|
|
133
141
|
## Test data
|
134
142
|
|
@@ -136,4 +144,3 @@ puts parsed.to_html
|
|
136
144
|
real-world ingredient lists found on the Dutch market. Each line contains one ingredient
|
137
145
|
list (newlines are encoded as `\n`, empty lines and those starting with `#` are ignored).
|
138
146
|
Currently almost three quarter is recognized and parsed. We aim to reach at least 90%.
|
139
|
-
|
@@ -4,7 +4,7 @@ require 'food_ingredient_parser/version'
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'food_ingredient_parser'
|
6
6
|
s.version = FoodIngredientParser::VERSION
|
7
|
-
s.date =
|
7
|
+
s.date = FoodIngredientParser::VERSION_DATE
|
8
8
|
s.summary = 'Parser for ingredient lists found on food products.'
|
9
9
|
s.authors = ['wvengen']
|
10
10
|
s.email = ['dev-ruby@willem.engen.nl']
|
@@ -18,7 +18,7 @@ module FoodIngredientParser::ToHtml
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def node_to_html(node, cls=nil)
|
21
|
+
def node_to_html(node, cls=nil, depth=0)
|
22
22
|
el_cls = {} # map of node instances to class names for contained elements
|
23
23
|
terminal = node.terminal? # whether to look at children elements or not
|
24
24
|
|
@@ -30,12 +30,21 @@ module FoodIngredientParser::ToHtml
|
|
30
30
|
elsif node.is_a?(FoodIngredientParser::Grammar::IngredientNode)
|
31
31
|
el_cls[node.name] = "name" if node.respond_to?(:name)
|
32
32
|
el_cls[node.mark] = "mark" if node.respond_to?(:mark)
|
33
|
+
if node.respond_to?(:contains)
|
34
|
+
el_cls[node.contains] = "contains depth#{depth}"
|
35
|
+
depth += 1
|
36
|
+
end
|
37
|
+
elsif node.is_a?(FoodIngredientParser::Grammar::RootNode)
|
38
|
+
if node.respond_to?(:contains)
|
39
|
+
el_cls[node.contains] = "depth#{depth}"
|
40
|
+
depth += 1
|
41
|
+
end
|
33
42
|
end
|
34
43
|
|
35
44
|
val = if terminal
|
36
45
|
CGI.escapeHTML(node.text_value)
|
37
46
|
else
|
38
|
-
node.elements.map {|el| node_to_html(el, el_cls[el]) }.join("")
|
47
|
+
node.elements.map {|el| node_to_html(el, el_cls[el], depth) }.join("")
|
39
48
|
end
|
40
49
|
|
41
50
|
cls ? "<span class='#{cls}'>#{val}</span>" : val
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: food_ingredient_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wvengen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|