attentive 0.3.3 → 0.3.4

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: 83c00c687fb2775e98c9241f3d5b50cfeda1f081
4
- data.tar.gz: 160136973d7d6f3a6b3c661a0f91259a2b719a4c
3
+ metadata.gz: 30975536bce928d23402e0042c837b4632e1736a
4
+ data.tar.gz: 404d44e02460fe642bda70f08264b51f894f4eaa
5
5
  SHA512:
6
- metadata.gz: e4b1788cecb43890e207c919be1061cff04a894035e4fa343bf6b66302d54b8cd20e97b86e384e2626519821e539a34511f27a28c968ad0766330dfaa4166950
7
- data.tar.gz: 76a8fa1d38d9a6800b07f2fa72fbe47589b1186a87ca779de832627c64edde5c3be48f8dbb013087ba128f5168f826252f0aff915c897bccdbb1353055f4ac7f
6
+ metadata.gz: b1a9416baceffca676810f74519fe64bf55d2b1ec6c131aa99defc4941c9f80d34d4a051f918800f0b7cf28258134acd2df9daa613975e86fbe029cf2ee27725
7
+ data.tar.gz: 7e5ca689fb5554f023eeacb5695e423f4f25e1a568900fe9d2b69a9488f2fa04b2be5de9194aa4cc4074be2b3ed19309338a6ab85d0bc507077ad1bff80b0eac
@@ -1,5 +1,4 @@
1
1
  require "attentive/entity"
2
- require "date"
3
2
 
4
3
  Attentive::Entity.define "core.date.duration.units",
5
4
  "day",
@@ -0,0 +1,25 @@
1
+ require "attentive/entity"
2
+
3
+ Attentive::Entity.define "core.time.duration.units",
4
+ "second",
5
+ "seconds",
6
+ "s",
7
+ "minute",
8
+ "minutes",
9
+ "min",
10
+ "m",
11
+ "hour",
12
+ "hours",
13
+ "hr",
14
+ "hrs",
15
+ "h",
16
+ published: false do |match|
17
+
18
+ case match.phrase
19
+ when "second", "seconds", "s" then :seconds
20
+ when "minute", "minutes", "min", "m" then :minutes
21
+ when "hour", "hours", "hr", "hrs", "h" then :hours
22
+ else
23
+ nomatch!
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require "attentive/entity"
2
+ require "attentive/duration"
3
+ require "attentive/entities/core/time/duration/units"
4
+
5
+ Attentive::Entity.define "core.time.duration.single",
6
+ "{{n:core.number.integer.positive}} {{unit:core.time.duration.units}}",
7
+ published: false do |match|
8
+
9
+ unit = match["unit"]
10
+ n = match["n"]
11
+ Attentive::Duration.new(unit => n)
12
+
13
+ end
14
+
15
+ Attentive::Entity.define "core.time.duration",
16
+ %q{(?:(?<hours>\d\d?):(?<minutes>\d\d):(?<seconds>\d\d))},
17
+ "{{a:core.time.duration.single}} {{b:core.time.duration}}",
18
+ "{{a:core.time.duration.single}} and {{b:core.time.duration}}",
19
+ "{{a:core.time.duration.single}}" do |match|
20
+
21
+ if match.matched?("hours")
22
+ return Attentive::Duration.new(
23
+ hours: match["hours"],
24
+ minutes: match["minutes"],
25
+ seconds: match["seconds"])
26
+ else
27
+ a = match["a"]
28
+ a += match["b"] if match.matched?("b")
29
+ a
30
+ end
31
+
32
+ end
@@ -0,0 +1,31 @@
1
+ require "attentive/entities/core/time/duration"
2
+ require "date"
3
+ require "time"
4
+
5
+ Attentive::Entity.define "core.time",
6
+ "noon",
7
+ "midnight",
8
+ %q{(?:(?<hours>\d\d?):(?<minutes>\d\d)\s*(?<pm>pm?))},
9
+ %q{(?:(?<hours>\d\d?)\s*(?:am?|(?<pm>pm?)))},
10
+ %q{(?:(?<hours>\d\d?):(?<minutes>\d\d))} do |match|
11
+
12
+ minutes = 0
13
+
14
+ p match
15
+ if match.matched?("hours")
16
+ hours = match["hours"].to_i
17
+ hours += 12 if match.matched?("pm")
18
+ minutes = match["minutes"].to_i if match.matched?("minutes")
19
+ else
20
+ case match.to_s
21
+ when "noon" then hours = 12
22
+ when "midnight" then hours = 0
23
+ else nomatch!
24
+ end
25
+ end
26
+
27
+ nomatch! if hours < 0 || hours > 24
28
+ nomatch! if minutes < 0 || minutes > 60
29
+
30
+ today = Date.today; Time.new(today.year, today.month, today.day, hours, minutes)
31
+ end
@@ -1,3 +1,4 @@
1
1
  require "attentive/entities/core/number"
2
2
  require "attentive/entities/core/date"
3
+ require "attentive/entities/core/time"
3
4
  require "attentive/entities/core/email"
@@ -12,7 +12,7 @@ module Attentive
12
12
  end
13
13
 
14
14
  def matched?(variable_name)
15
- @match_data.key? variable_name.to_s
15
+ !@match_data[variable_name.to_s].nil?
16
16
  end
17
17
 
18
18
  def [](variable_name)
@@ -1,3 +1,3 @@
1
1
  module Attentive
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attentive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-17 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_safe
@@ -196,6 +196,9 @@ files:
196
196
  - lib/attentive/entities/core/number/integer/positive.rb
197
197
  - lib/attentive/entities/core/number/negative.rb
198
198
  - lib/attentive/entities/core/number/positive.rb
199
+ - lib/attentive/entities/core/time.rb
200
+ - lib/attentive/entities/core/time/duration.rb
201
+ - lib/attentive/entities/core/time/duration/units.rb
199
202
  - lib/attentive/entity.rb
200
203
  - lib/attentive/errors.rb
201
204
  - lib/attentive/listener.rb