projectsimulator 0.2.0 → 0.2.1
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/projectsimulator.rb +73 -9
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 024bbe43574b19e2cef1d32997464cb570ae9828559842a47980069503d4ccd4
|
4
|
+
data.tar.gz: ac1aac4437f90007c016ef61e7b6bf89673d6d1310929e9557e1f334e730198d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c18c8f2422750ffa91db344a0d9845633be16d23447599e9c73404bf2203335a110f0fa56f45cf5e552aa2ef66740c18d4d1de3ee9cdbca72d4602aaa203528b
|
7
|
+
data.tar.gz: 349887e64fcd35c9bfadbb113e52cea58a7f781b58896e1888dd9763e064d9b38a4917e6622f9bee7334a1ebb186d1abda4048bfa4c154b448a6953507000892
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/projectsimulator.rb
CHANGED
@@ -162,15 +162,31 @@ module ProjectSimulator
|
|
162
162
|
@messages = []
|
163
163
|
|
164
164
|
h = {motion: MotionTrigger}
|
165
|
-
|
166
|
-
|
165
|
+
|
166
|
+
if @triggers.any? {|x| x.is_a? h[trigger.to_sym] and x.match } then
|
167
|
+
|
168
|
+
if @constraints.all?(&:match) then
|
167
169
|
|
168
|
-
|
170
|
+
@messages = @actions.map(&:call)
|
171
|
+
|
172
|
+
else
|
173
|
+
|
174
|
+
puts 'else reset?' if @debug
|
175
|
+
a = @constraints.select {|x| x.is_a? FrequencyConstraint }
|
176
|
+
puts 'a:' + a.inspect if @debug
|
177
|
+
a.each {|x| x.reset if x.counter > 0 }
|
178
|
+
return false
|
179
|
+
end
|
169
180
|
|
170
181
|
end
|
171
182
|
|
172
183
|
end
|
173
|
-
|
184
|
+
|
185
|
+
def time=(val)
|
186
|
+
@time = val
|
187
|
+
@constraints.each {|x| x.time = val if x.is_a? TimeConstraint }
|
188
|
+
end
|
189
|
+
|
174
190
|
end
|
175
191
|
|
176
192
|
class Action
|
@@ -291,6 +307,10 @@ module ProjectSimulator
|
|
291
307
|
get /^(after .*)/i do |s|
|
292
308
|
TimeConstraint.new(s, time: @time)
|
293
309
|
end
|
310
|
+
|
311
|
+
get /^once only/i do |s|
|
312
|
+
FrequencyConstraint.new(1, debug: @debug)
|
313
|
+
end
|
294
314
|
|
295
315
|
end
|
296
316
|
|
@@ -340,15 +360,46 @@ module ProjectSimulator
|
|
340
360
|
|
341
361
|
end
|
342
362
|
|
343
|
-
class TimeConstraint
|
363
|
+
class TimeConstraint
|
344
364
|
|
345
|
-
|
365
|
+
attr_accessor :time
|
346
366
|
|
347
367
|
def initialize(times, time: nil)
|
348
|
-
@
|
368
|
+
@times, @time = times, time
|
369
|
+
end
|
370
|
+
|
371
|
+
def match()
|
372
|
+
ChronicBetween.new(@times).within?(@time)
|
349
373
|
end
|
350
374
|
|
351
|
-
end
|
375
|
+
end
|
376
|
+
|
377
|
+
class FrequencyConstraint
|
378
|
+
|
379
|
+
def initialize(freq, debug: false)
|
380
|
+
@freq, @debug = freq, debug
|
381
|
+
@counter = 0
|
382
|
+
end
|
383
|
+
|
384
|
+
def counter()
|
385
|
+
@counter
|
386
|
+
end
|
387
|
+
|
388
|
+
def increment()
|
389
|
+
@counter += 1
|
390
|
+
end
|
391
|
+
|
392
|
+
def match()
|
393
|
+
@counter < @freq
|
394
|
+
end
|
395
|
+
|
396
|
+
def reset()
|
397
|
+
puts 'resetting' if @debug
|
398
|
+
@foo = 0
|
399
|
+
@counter = 0
|
400
|
+
end
|
401
|
+
|
402
|
+
end
|
352
403
|
|
353
404
|
class Controller
|
354
405
|
|
@@ -366,16 +417,29 @@ module ProjectSimulator
|
|
366
417
|
|
367
418
|
end
|
368
419
|
|
420
|
+
def time=(val)
|
421
|
+
@time = val
|
422
|
+
@events.each {|event| event.time = val }
|
423
|
+
end
|
424
|
+
|
369
425
|
def trigger(name, location: '')
|
370
426
|
|
371
427
|
events = @events.select do |event|
|
372
428
|
|
373
429
|
puts 'event: ' + event.inspect if @debug
|
374
430
|
|
375
|
-
event.match(trigger: 'motion', location: location
|
431
|
+
event.match(trigger: 'motion', location: location)
|
376
432
|
|
377
433
|
end
|
378
434
|
|
435
|
+
puts 'events: ' + events.inspect if @debug
|
436
|
+
|
437
|
+
events.each do |event|
|
438
|
+
c = event.constraints.select {|x| x.is_a? FrequencyConstraint }
|
439
|
+
puts 'c:' + c.inspect
|
440
|
+
c.each(&:increment)
|
441
|
+
end
|
442
|
+
|
379
443
|
events.flat_map(&:messages)
|
380
444
|
|
381
445
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: projectsimulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
2GrtfOXGVOS+2jvmCQC6vU+ew9WBxiDUbebI95TeTwMs2o0cs3IASXX5rIn4TPcz
|
36
36
|
SCccB3fVg2yfsy5DivaWaZwg
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-05-
|
38
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rowx
|
metadata.gz.sig
CHANGED
Binary file
|