attentive 0.3.7 → 0.3.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82d538262cfb344744d56a62ab0c55ead35d0513
4
- data.tar.gz: 2cf0add3bcd0f0a0535d449fc4cd3df181315486
3
+ metadata.gz: 8669ab83c07030dc94a2a923b16c61069806b852
4
+ data.tar.gz: 33113394ce4f54e4c74fdcfaee93c5698b9c33de
5
5
  SHA512:
6
- metadata.gz: c4f978dd2eeab193511fc4e19aba9860d5c7407b825a459db411d81bdae24e4692de47aedf9598cda634d774904456d3192f686b4acb67fdf6b333bea965ea9f
7
- data.tar.gz: d2ea36e5454a21a65c1f75b288fbfc2439a8d892255a8e07d917bc45520d97612ceb428bba4d1d654d81ddb93c31ca17eea1298180d35101e70186e8ffcda909
6
+ metadata.gz: 9c35dd50589ae502571ec8260285dc21abe88a0eb970685339dc6d81f50f3519ae8e1afb06669c5f690cef58917cf2364ff024f8df3c85ec44f858bdf931ad22
7
+ data.tar.gz: 271d287cc592f2188136102853eb1518a10ff6b772fc482f5ee5988164cad6ecf7d622f5c41ec41160b539f64289db32a4fdbc624595c0f9cb9ba614b109d377
@@ -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
- entity_klass.send :define_method, :_value_from_match, &block if block_given?
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
 
@@ -1,3 +1,3 @@
1
1
  module Attentive
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attentive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail