attentive 0.3.4 → 0.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c2dd05878b484a741af79656ca91f860f4ee6cb
|
4
|
+
data.tar.gz: ae71608dbc82bb68eddfc8ecf9c1f6a96543d67b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b8bc10ea59c099b916e8765bedcdef39119bb463dcf09eed8dfe39564ef174a15e6cb3dd98fe0fc2d83c185114c230e3d7d9086149a680a5bee9943e4d62f5
|
7
|
+
data.tar.gz: 2f14b5a1ad5dda7bb1e9fc694ba9bd670cbd51a3ac134c06f999ba2ab8f9f24f1146cc68b629311341ed8d40355119e42f34cd754db9a2e4a3313e7de8a5aad5
|
data/lib/attentive/duration.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
module Attentive
|
2
|
-
class Duration < Struct.new(:years, :months, :days)
|
2
|
+
class Duration < Struct.new(:years, :months, :days, :hours, :minutes, :seconds)
|
3
3
|
|
4
4
|
def initialize(attributes)
|
5
5
|
super(
|
6
6
|
attributes.fetch(:years, 0),
|
7
7
|
attributes.fetch(:months, 0),
|
8
|
-
attributes.fetch(:days, 0)
|
8
|
+
attributes.fetch(:days, 0),
|
9
|
+
attributes.fetch(:hours, 0),
|
10
|
+
attributes.fetch(:minutes, 0),
|
11
|
+
attributes.fetch(:seconds, 0))
|
9
12
|
end
|
10
13
|
|
11
14
|
def +(other)
|
12
15
|
self.class.new(
|
13
16
|
years: years + other.years,
|
14
17
|
months: months + other.months,
|
15
|
-
days: days + other.days
|
18
|
+
days: days + other.days,
|
19
|
+
hours: hours + other.hours,
|
20
|
+
minutes: minutes + other.minutes,
|
21
|
+
seconds: seconds + other.seconds)
|
16
22
|
end
|
17
23
|
|
18
24
|
def inspect
|
@@ -20,6 +26,9 @@ module Attentive
|
|
20
26
|
phrases.push "#{years} years" if years > 0
|
21
27
|
phrases.push "#{months} months" if months > 0
|
22
28
|
phrases.push "#{days} days" if days > 0
|
29
|
+
phrases.push "#{hours} hours" if hours > 0
|
30
|
+
phrases.push "#{minutes} minutes" if minutes > 0
|
31
|
+
phrases.push "#{seconds} seconds" if seconds > 0
|
23
32
|
"<#{phrases.join(" ")}>"
|
24
33
|
end
|
25
34
|
|
@@ -20,9 +20,9 @@ Attentive::Entity.define "core.time.duration",
|
|
20
20
|
|
21
21
|
if match.matched?("hours")
|
22
22
|
return Attentive::Duration.new(
|
23
|
-
hours: match["hours"],
|
24
|
-
minutes: match["minutes"],
|
25
|
-
seconds: match["seconds"])
|
23
|
+
hours: match["hours"].to_i,
|
24
|
+
minutes: match["minutes"].to_i,
|
25
|
+
seconds: match["seconds"].to_i)
|
26
26
|
else
|
27
27
|
a = match["a"]
|
28
28
|
a += match["b"] if match.matched?("b")
|
data/lib/attentive/matcher.rb
CHANGED
@@ -4,6 +4,12 @@ module Attentive
|
|
4
4
|
class Matcher
|
5
5
|
attr_reader :phrase, :message, :cursor
|
6
6
|
|
7
|
+
def self.match!(phrase, message)
|
8
|
+
phrase = Attentive::Tokenizer.tokenize(phrase, entities: true) unless phrase.is_a?(Attentive::Phrase)
|
9
|
+
message = Attentive::Message.new(message) unless message.is_a?(Attentive::Message)
|
10
|
+
self.new(phrase, Attentive::Cursor.new(message)).match!
|
11
|
+
end
|
12
|
+
|
7
13
|
def initialize(phrase, message, params={})
|
8
14
|
@phrase = phrase
|
9
15
|
@match_start = message.pos
|
data/lib/attentive/version.rb
CHANGED