attentive 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30975536bce928d23402e0042c837b4632e1736a
4
- data.tar.gz: 404d44e02460fe642bda70f08264b51f894f4eaa
3
+ metadata.gz: 9c2dd05878b484a741af79656ca91f860f4ee6cb
4
+ data.tar.gz: ae71608dbc82bb68eddfc8ecf9c1f6a96543d67b
5
5
  SHA512:
6
- metadata.gz: b1a9416baceffca676810f74519fe64bf55d2b1ec6c131aa99defc4941c9f80d34d4a051f918800f0b7cf28258134acd2df9daa613975e86fbe029cf2ee27725
7
- data.tar.gz: 7e5ca689fb5554f023eeacb5695e423f4f25e1a568900fe9d2b69a9488f2fa04b2be5de9194aa4cc4074be2b3ed19309338a6ab85d0bc507077ad1bff80b0eac
6
+ metadata.gz: c3b8bc10ea59c099b916e8765bedcdef39119bb463dcf09eed8dfe39564ef174a15e6cb3dd98fe0fc2d83c185114c230e3d7d9086149a680a5bee9943e4d62f5
7
+ data.tar.gz: 2f14b5a1ad5dda7bb1e9fc694ba9bd670cbd51a3ac134c06f999ba2ab8f9f24f1146cc68b629311341ed8d40355119e42f34cd754db9a2e4a3313e7de8a5aad5
@@ -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
 
@@ -11,7 +11,6 @@ Attentive::Entity.define "core.time",
11
11
 
12
12
  minutes = 0
13
13
 
14
- p match
15
14
  if match.matched?("hours")
16
15
  hours = match["hours"].to_i
17
16
  hours += 12 if match.matched?("pm")
@@ -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")
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Attentive
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
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.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail