attentive 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attentive/entity.rb +16 -1
- data/lib/attentive/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8669ab83c07030dc94a2a923b16c61069806b852
|
4
|
+
data.tar.gz: 33113394ce4f54e4c74fdcfaee93c5698b9c33de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c35dd50589ae502571ec8260285dc21abe88a0eb970685339dc6d81f50f3519ae8e1afb06669c5f690cef58917cf2364ff024f8df3c85ec44f858bdf931ad22
|
7
|
+
data.tar.gz: 271d287cc592f2188136102853eb1518a10ff6b772fc482f5ee5988164cad6ecf7d622f5c41ec41160b539f64289db32a4fdbc624595c0f9cb9ba614b109d377
|
data/lib/attentive/entity.rb
CHANGED
@@ -30,12 +30,27 @@ module Attentive
|
|
30
30
|
def define(entity_name, *phrases, &block)
|
31
31
|
options = phrases.last.is_a?(::Hash) ? phrases.pop : {}
|
32
32
|
|
33
|
+
phrase_value_map = {}
|
34
|
+
options.each do |phrase, value|
|
35
|
+
next if phrase.is_a?(Symbol) # symbols are options, strings are phrases
|
36
|
+
options.delete phrase
|
37
|
+
phrase_value_map[phrase] = value
|
38
|
+
phrases.push phrase
|
39
|
+
end
|
40
|
+
|
33
41
|
create! entity_name do |entity_klass|
|
34
42
|
entity_klass.phrases = phrases.map do |phrase|
|
35
43
|
Attentive::Tokenizer.tokenize(phrase, entities: true, regexps: true)
|
36
44
|
end
|
37
45
|
entity_klass.published = options.fetch(:published, true)
|
38
|
-
|
46
|
+
|
47
|
+
if block_given?
|
48
|
+
entity_klass.send :define_method, :_value_from_match, &block
|
49
|
+
else
|
50
|
+
entity_klass.send :define_method, :_value_from_match do |match|
|
51
|
+
phrase_value_map.fetch(match.to_s, match.to_s)
|
52
|
+
end
|
53
|
+
end
|
39
54
|
end
|
40
55
|
end
|
41
56
|
|
data/lib/attentive/version.rb
CHANGED