spstrigger_execute 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d28d7b4b5d0fa20d6d2cda77da1ba889022d7505
4
+ data.tar.gz: c2b091ae0270b4d0100cdbec9d88b5cdbdd5c02f
5
+ SHA512:
6
+ metadata.gz: 0b43ebbf211554f83c00854ad8fa2e0324b4ca362b87b443d2fff14e8eefbf7383d8659f48534d3c9f31cba6f36497e84d966b16c849825c5b2adf395c4c793e
7
+ data.tar.gz: 741103b3dd1913a9c3f28340d35e8ecdf785e22f6fae834a5e911880e8f69f24fa4c7e1cd85ade558bf5ecbe2948a5171e6eae546c0172a7b5f03fd3d6d34300
@@ -0,0 +1,2 @@
1
+ �e7K�!E��cx���P9�����*y-G9~�s����I�_�%�n�2`�聳vAGG�R{)F������oR�W�tc�e�F��f�sK/��p�x�[�L׉��c+�W$��Ww�r�j�������7H�� EN���^uح���=���I�#�Ӯ ݍ9�)�
2
+ �O���%s�ef?Җ�_?z�޶ۉ�(L������ Dc��ܨ�)� t��r�ө��9�p�^]+���5"�A$UE��O��
Binary file
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: spstrigger_execute.rb
4
+
5
+ require 'dynarex'
6
+ require 'chronic_between'
7
+
8
+
9
+ class SPSTriggerExecute
10
+
11
+ def initialize(url_lookup)
12
+
13
+ @patterns = Dynarex.new(url_lookup).to_h
14
+
15
+ end
16
+
17
+ def match_and_execute(topicx, message)
18
+ results = find_match topicx, message
19
+ prepare_jobs(results, @obj, @ws)
20
+ end
21
+
22
+ alias mae match_and_execute
23
+
24
+ private
25
+
26
+ def find_match(topicx, message)
27
+
28
+ @patterns.map.with_index.inject([]) do |r, row|
29
+
30
+ h, i = row
31
+ topic, msg, conditions, job, index = h.values
32
+
33
+ index ||= i + 1
34
+
35
+ # note: the index is only present if there is a duplicate Dynarex record default key
36
+
37
+ t, m = topic.length > 0, msg.length > 0
38
+
39
+ result = if t && m then
40
+
41
+ r1 = topicx.match(/#{topic}/)
42
+ r2 = message.match(/#{msg}/)
43
+
44
+ {topic: r1, msg: r2, index: index} if r1 && r2
45
+
46
+ elsif t then
47
+
48
+ r1 = topicx.match(/#{topic}/)
49
+ {topic: r1, index: index} if r1
50
+
51
+ elsif m then
52
+
53
+ r2 = message.match(/#{msg}/)
54
+ {msg: r2, index: index} if r2
55
+ else
56
+ {}
57
+ end
58
+
59
+ if conditions.length > 0 then
60
+ puts '** h : ' + h.inspect
61
+ time = time
62
+ end
63
+
64
+ result ? r << result : r
65
+
66
+ end
67
+ end
68
+
69
+ def prepare_jobs(results,obj, ws)
70
+
71
+ results.inject([]) do |r,h|
72
+
73
+ a = []
74
+ a += h[:topic].captures if h[:topic] && h[:topic].captures.any?
75
+ a += h[:msg].captures if h[:msg]
76
+
77
+ job = @patterns[h[:index].to_i - 1][:job]
78
+ job_args = job.split + a
79
+
80
+ if job[/^\/\//] then
81
+
82
+ r << [:rse, job_args]
83
+
84
+ else
85
+
86
+ topic_message = job.gsub(/\$\d/) do |x|
87
+
88
+ i = x[/\d$/].to_i - 1
89
+ x.sub(/\$\d/, a3[i])
90
+ end
91
+
92
+ topic_message = topic_message\
93
+ .gsub(/![Tt]ime/,Time.now.strftime("%a %H:%M%P"))\
94
+ .gsub(/![Dd]ate/,Time.now.strftime("%d %b"))
95
+ puts 'publishing :' + topic_message.inspect
96
+
97
+ topic_message.split(/\s*;\s*/).each do |m|
98
+
99
+ r << [:sps, m]
100
+
101
+ end
102
+
103
+ end
104
+ r
105
+ end
106
+ end
107
+
108
+ def time()
109
+
110
+ t = Time.now
111
+
112
+ def t.within?(times)
113
+ ChronicBetween.new(times).within? Time.now
114
+ end
115
+
116
+ t
117
+ end
118
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spstrigger_execute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James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sRE11mlRiQOiKZDqsw8/Y9D/yRSH4dY3Gq3xQY
28
+ W2XxMR0okW/bPfSq3IU/gjukc6yqI7A3rU4F7+idbHIhiHLhtS6oaaCFCwIWT8nU
29
+ YpibuWDr8aRAOfhsU0kLOJbJgSetnWBqOaxGXD17OtmQUkK9iMTbdxRotRXauHWb
30
+ flYpNYm4CG+D4ZdG69glQaJLQ/qBbtLVwwnrsmVyEeWMIKCws0ttVzM1PO54I83p
31
+ rlSMrvljzPJPts27UIPIfU02mkTZzELneWPUEQlIK/ADjdiGu2uxlWT5g77gwM+g
32
+ fYtWdC+NEqa0rg==
33
+ -----END CERTIFICATE-----
34
+ date: 2015-03-05 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: dynarex
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.5'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.5'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.5.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: chronic_between
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.2.22
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.2'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.22
76
+ description:
77
+ email: james@r0bertson.co.uk
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/spstrigger_execute.rb
83
+ homepage: https://github.com/jrobertson/spstrigger_execute
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: An SPS client built for reponding to messages which match keywords and conditions.
107
+ test_files: []
Binary file