projectsimulator 0.2.1 → 0.2.2
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/lib/projectsimulator.rb +126 -17
- data.tar.gz.sig +0 -0
- metadata +1 -1
- 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: 004c088ecb944c24b758301d5cd41fe5a9135b6401b5c489bbac794a951ad17e
|
4
|
+
data.tar.gz: d5ce967f78e745769888e57b0f3342f1c2669280923bbd699f55a066f84fc5de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35fbc194fa72f2fa1b8081259504e62abe03b47336b8bbf952957b172f2d19276296278406a0db710a8dca39e9d798bb4514de397d429cabcf981085a7272c53
|
7
|
+
data.tar.gz: 5de28c8c32f433c3efe1cad7b90cd0111ac69025fa40ed4d28e75cd14ae35c52a755feb3ce899ccd27836bc6c61218292cf0789def2baa6812c644c0d219a0c3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/projectsimulator.rb
CHANGED
@@ -134,7 +134,7 @@ module ProjectSimulator
|
|
134
134
|
attr_accessor :title
|
135
135
|
attr_reader :triggers, :actions, :constraints, :messages
|
136
136
|
|
137
|
-
def initialize(e, time: nil, debug: false)
|
137
|
+
def initialize(e, time: nil, title: '', debug: false)
|
138
138
|
|
139
139
|
@time, @debug = time, debug
|
140
140
|
@title = e.text('event')
|
@@ -142,17 +142,19 @@ module ProjectSimulator
|
|
142
142
|
@triggers = []
|
143
143
|
@constraints = []
|
144
144
|
|
145
|
-
e.xpath('trigger
|
146
|
-
@triggers << Trigger.new(x, time: time, debug: debug)
|
145
|
+
e.xpath('trigger').each do |x|
|
146
|
+
@triggers << Trigger.new(x.text().strip, time: time, debug: debug)\
|
147
|
+
.to_type
|
147
148
|
end
|
148
149
|
|
149
|
-
e.xpath('action
|
150
|
-
@actions << Action.new(x, debug: debug).to_type
|
150
|
+
e.xpath('action').each do |x|
|
151
|
+
@actions << Action.new(x.text().strip, debug: debug).to_type
|
151
152
|
end
|
152
153
|
|
153
|
-
e.xpath('constraint
|
154
|
+
e.xpath('constraint').each do |x|
|
154
155
|
puts 'before Constraints.new'
|
155
|
-
@constraints << Constraint.new(x,
|
156
|
+
@constraints << Constraint.new(x.text().strip, \
|
157
|
+
time: time, debug: debug).to_type
|
156
158
|
end
|
157
159
|
|
158
160
|
end
|
@@ -187,6 +189,34 @@ module ProjectSimulator
|
|
187
189
|
@constraints.each {|x| x.time = val if x.is_a? TimeConstraint }
|
188
190
|
end
|
189
191
|
|
192
|
+
def to_node()
|
193
|
+
|
194
|
+
e = Rexle::Element.new(:event, attributes: {title: @title})
|
195
|
+
|
196
|
+
e.add node_collection(:triggers, @triggers)
|
197
|
+
e.add node_collection(:actions, @actions)
|
198
|
+
e.add node_collection(:constraints, @constraints)
|
199
|
+
|
200
|
+
return e
|
201
|
+
end
|
202
|
+
|
203
|
+
def to_rowx()
|
204
|
+
|
205
|
+
s = "event: %s\n\n" % @title
|
206
|
+
s + [@triggers, @actions, @constraints]\
|
207
|
+
.map {|x| x.collect(&:to_rowx).join("\n")}.join("\n")
|
208
|
+
end
|
209
|
+
|
210
|
+
private
|
211
|
+
|
212
|
+
def node_collection(name, a)
|
213
|
+
|
214
|
+
e = Rexle::Element.new(name)
|
215
|
+
a.each {|x| e.add x.to_node}
|
216
|
+
return e
|
217
|
+
|
218
|
+
end
|
219
|
+
|
190
220
|
end
|
191
221
|
|
192
222
|
class Action
|
@@ -308,9 +338,21 @@ module ProjectSimulator
|
|
308
338
|
TimeConstraint.new(s, time: @time)
|
309
339
|
end
|
310
340
|
|
311
|
-
get /^once only
|
341
|
+
get /^once only|only once|once|one time|1 time$/i do |s|
|
312
342
|
FrequencyConstraint.new(1, debug: @debug)
|
313
|
-
end
|
343
|
+
end
|
344
|
+
|
345
|
+
get /^twice only|only twice|twice|two times|2 times$/i do |s|
|
346
|
+
FrequencyConstraint.new(2, debug: @debug)
|
347
|
+
end
|
348
|
+
|
349
|
+
get /^(Maximum|Max|Up to) ?three times|3 times$/i do |s|
|
350
|
+
FrequencyConstraint.new(3, debug: @debug)
|
351
|
+
end
|
352
|
+
|
353
|
+
get /^(Maximum|Max|Up to) ?four times|4 times$/i do |s|
|
354
|
+
FrequencyConstraint.new(4, debug: @debug)
|
355
|
+
end
|
314
356
|
|
315
357
|
end
|
316
358
|
|
@@ -323,25 +365,42 @@ module ProjectSimulator
|
|
323
365
|
|
324
366
|
attr_reader :location
|
325
367
|
|
326
|
-
def initialize(location)
|
368
|
+
def initialize(locationx, location: locationx)
|
327
369
|
@location = location
|
328
370
|
end
|
329
371
|
|
330
372
|
def match()
|
331
373
|
@location.downcase == location.downcase
|
332
374
|
end
|
375
|
+
|
376
|
+
def to_node()
|
377
|
+
Rexle::Element.new(:trigger, \
|
378
|
+
attributes: {type: :motion, location: @location})
|
379
|
+
end
|
380
|
+
|
381
|
+
def to_rowx()
|
382
|
+
"trigger: Motion detected in the %s" % @location
|
383
|
+
end
|
333
384
|
|
334
385
|
end
|
335
386
|
|
336
387
|
class SayAction
|
337
388
|
|
338
|
-
def initialize(s)
|
389
|
+
def initialize(s, text: s)
|
339
390
|
@s = s
|
340
391
|
end
|
341
392
|
|
342
393
|
def call()
|
343
394
|
"say: %s" % @s
|
344
395
|
end
|
396
|
+
|
397
|
+
def to_node()
|
398
|
+
Rexle::Element.new(:action, attributes: {type: :say, text: @s})
|
399
|
+
end
|
400
|
+
|
401
|
+
def to_rowx()
|
402
|
+
"action: say %s" % @s
|
403
|
+
end
|
345
404
|
|
346
405
|
end
|
347
406
|
|
@@ -349,14 +408,24 @@ module ProjectSimulator
|
|
349
408
|
|
350
409
|
attr_accessor :url
|
351
410
|
|
352
|
-
def initialize(name)
|
411
|
+
def initialize(namex, name: namex, url: '127.0.0.1')
|
353
412
|
@name = name
|
354
|
-
@url =
|
413
|
+
@url = url
|
355
414
|
end
|
356
415
|
|
357
416
|
def call()
|
358
417
|
"webhook: %s" % @url
|
359
418
|
end
|
419
|
+
|
420
|
+
def to_node()
|
421
|
+
Rexle::Element.new(:action, \
|
422
|
+
attributes: {type: :webhook, name: @name, url: @url})
|
423
|
+
end
|
424
|
+
|
425
|
+
def to_rowx()
|
426
|
+
s = "action: webhook %s" % @name
|
427
|
+
s += "\n url: %s" % @url
|
428
|
+
end
|
360
429
|
|
361
430
|
end
|
362
431
|
|
@@ -364,19 +433,28 @@ module ProjectSimulator
|
|
364
433
|
|
365
434
|
attr_accessor :time
|
366
435
|
|
367
|
-
def initialize(times, time: nil)
|
436
|
+
def initialize(timesx, times: timesx, time: nil)
|
368
437
|
@times, @time = times, time
|
369
438
|
end
|
370
439
|
|
371
440
|
def match()
|
372
441
|
ChronicBetween.new(@times).within?(@time)
|
373
442
|
end
|
443
|
+
|
444
|
+
def to_node()
|
445
|
+
Rexle::Element.new(:constraint, \
|
446
|
+
attributes: {type: :time, times: @times})
|
447
|
+
end
|
448
|
+
|
449
|
+
def to_rowx()
|
450
|
+
"constraint: %s" % @times
|
451
|
+
end
|
374
452
|
|
375
453
|
end
|
376
454
|
|
377
455
|
class FrequencyConstraint
|
378
456
|
|
379
|
-
def initialize(freq, debug: false)
|
457
|
+
def initialize(freqx, freq: freqx, debug: false)
|
380
458
|
@freq, @debug = freq, debug
|
381
459
|
@counter = 0
|
382
460
|
end
|
@@ -395,8 +473,27 @@ module ProjectSimulator
|
|
395
473
|
|
396
474
|
def reset()
|
397
475
|
puts 'resetting' if @debug
|
398
|
-
@
|
399
|
-
|
476
|
+
@counter = 0
|
477
|
+
end
|
478
|
+
|
479
|
+
def to_node()
|
480
|
+
Rexle::Element.new(:constraint, \
|
481
|
+
attributes: {type: :frequency, freq: @freq})
|
482
|
+
end
|
483
|
+
|
484
|
+
def to_rowx()
|
485
|
+
|
486
|
+
freq = case @freq
|
487
|
+
when 1
|
488
|
+
'Once'
|
489
|
+
when 2
|
490
|
+
'Twice'
|
491
|
+
else
|
492
|
+
"Maximum %s times" % @freq
|
493
|
+
end
|
494
|
+
|
495
|
+
"constraint: %s" % freq
|
496
|
+
|
400
497
|
end
|
401
498
|
|
402
499
|
end
|
@@ -422,6 +519,18 @@ module ProjectSimulator
|
|
422
519
|
@events.each {|event| event.time = val }
|
423
520
|
end
|
424
521
|
|
522
|
+
def to_doc()
|
523
|
+
|
524
|
+
doc = Rexle.new('<events/>')
|
525
|
+
@events.each {|event| doc.root.add event.to_node }
|
526
|
+
return doc
|
527
|
+
|
528
|
+
end
|
529
|
+
|
530
|
+
def to_rowx()
|
531
|
+
@events.collect(&:to_rowx).join("\n\n#{'-'*50}\n\n")
|
532
|
+
end
|
533
|
+
|
425
534
|
def trigger(name, location: '')
|
426
535
|
|
427
536
|
events = @events.select do |event|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|