kanal 0.4.2 → 0.4.3

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
  SHA256:
3
- metadata.gz: 3a651f7ffee3a091afafa59e96d5c4e90d3f15ebd8fe5c0991ef0f3d25559cb5
4
- data.tar.gz: 80a337f6047a542982f5167a1a15c73a9df90ffa95d6d24dc07bba881a4f575e
3
+ metadata.gz: b0a793b05b3b6a5848b173907c41e64b0fd40c1a68b7b992c784923dbd34c1df
4
+ data.tar.gz: 01cab2e1b68b1c0d7559208a47883caccfd7a7c1019f4e740c12bdb28129e329
5
5
  SHA512:
6
- metadata.gz: 69b67d9f7886722abe0cc0b8ba27e30daecde925a275e3147b38c5b80bb1b9d041d1acdd33151be97c8e4a668888fbcf1819192dceb763e52104bfaa97a56ce4
7
- data.tar.gz: fb12441c0c5797397cbc40e4517cc23c6a70c6604a0314961d4c9b203c02130464baefda7c6671cd31733112d4f131076de3d92482d695f10b7898c7b5c7b2c8
6
+ metadata.gz: dca772528cfca7d06de8f48c2a3da90fc99615d1ad06b2dd0b6d6254e68e989937fb22b884aef9219a3a9d139dc2dc7a8d8e786e999dd52e81209739fc6d2d28
7
+ data.tar.gz: 7d8c3a80d26ceb6245154b694cafc8ca08fd742468cbf3fb6c332a3f064eee84ec20539a973d77494483f2a716d768a0c25fd80d06d9afba27d6d529f1d87882
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.3] 2023-03-30
4
+ - New condition for button pressed
5
+ - Input property button_pressed
6
+
3
7
  ## [0.4.2] 2023-03-22
4
8
  - Adding any number of loggers can be now done with core.add_logger(l) - where l is logger that have same methods as default ruby logger (debug, warn, fatal, etc)
5
9
  - To get logger into your class you can include Kanal::Core::Logging::Logger - this will give you method .logger to get logger
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kanal (0.4.2)
4
+ kanal (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -105,4 +105,4 @@ DEPENDENCIES
105
105
  yard
106
106
 
107
107
  BUNDLED WITH
108
- 2.3.19
108
+ 2.4.5
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../logging/composite_logger"
4
+
3
5
  module Kanal
4
6
  module Core
5
7
  module Helpers
@@ -8,22 +10,32 @@ module Kanal
8
10
  # get(name)
9
11
  # transforms unknown methods to setters/getters for parameters
10
12
  module ParameterFinderWithMethodMissingMixin
11
- def method_missing(symbol, *args)
13
+ include Logging::Logger
14
+
15
+ def method_missing(symbol, *args, &block)
16
+ if block && !args.first.nil?
17
+ logger.error "Block and arg given simultaneously. Parameter name: '#{symbol.to_s}, arg: #{args.first}'"
18
+
19
+ raise "Block and arg given simultaneously for parameter #{symbol.to_s}"
20
+ end
21
+
12
22
  parameter_name = symbol.to_s
13
23
  parameter_name.sub! "=", ""
14
24
 
15
25
  parameter_name = parameter_name.to_sym
16
26
 
27
+ value = block_given? ? block : args.first
28
+
17
29
  # standard workflow with settings properties with
18
30
  # input.prop = 123
19
31
  if symbol.to_s.include? "="
20
- @parameter_bag.set parameter_name, args.first
21
- elsif !args.empty?
32
+ @parameter_bag.set parameter_name, value
33
+ elsif !args.empty? || block_given?
22
34
  # this approach can be used also in dsl
23
35
  # like that
24
36
  # setters: prop value
25
37
  # getters: prop
26
- @parameter_bag.set parameter_name, args.first
38
+ @parameter_bag.set parameter_name, value
27
39
  # means it is used as setter in dsl,
28
40
  # method call with argument
29
41
  else
@@ -15,76 +15,25 @@ module Kanal
15
15
  @url = url
16
16
  end
17
17
 
18
- def audio?
19
- mp3? || wav? || ogg?
20
- end
21
-
22
- def mp3?
23
- extension == "mp3"
24
- end
25
-
26
- def wav?
27
- extension == "wav"
28
- end
29
-
30
- def ogg?
31
- extension == "ogg"
32
- end
33
-
34
- def document?
35
- doc? || docx? || odf?
36
- end
37
-
38
- def doc?
39
- extension == "doc"
40
- end
41
-
42
- def docx?
43
- extension == "docx"
44
- end
45
-
46
- def odf?
47
- extension == "odf"
18
+ # Extension checks like jpg?, mp3?, mp4?, doc? etc. fall here
19
+ def method_missing(method)
20
+ extension == method.to_s.delete("?")
48
21
  end
49
22
 
50
23
  def image?
51
- jpg? || jpeg? || png? || bpm? || gif?
52
- end
53
-
54
- def jpg?
55
- extension == "jpg"
56
- end
57
-
58
- def jpeg?
59
- extension == "jpeg"
60
- end
61
-
62
- def png?
63
- extension == "png"
24
+ [jpg?, jpeg?, png?, bmp?, gif?].any?
64
25
  end
65
26
 
66
- def bpm?
67
- extension == "bpm"
68
- end
69
-
70
- def gif?
71
- extension == "gif"
27
+ def audio?
28
+ [mp3?, wav?, ogg?].any?
72
29
  end
73
30
 
74
31
  def video?
75
- mp4? || mov? || mkv?
76
- end
77
-
78
- def mp4?
79
- extension == "mp4"
32
+ [mp4?, mov?, mkv?].any?
80
33
  end
81
34
 
82
- def mov?
83
- extension == "mov"
84
- end
85
-
86
- def mkv?
87
- extension == "mkv"
35
+ def document?
36
+ [doc?, docx?, odf?].any?
88
37
  end
89
38
 
90
39
  #
@@ -9,6 +9,8 @@ module Kanal
9
9
  module Batteries
10
10
  # Plugin with some batteries like .body property etc
11
11
  class BatteriesPlugin < Core::Plugins::Plugin
12
+
13
+
12
14
  def name
13
15
  :batteries
14
16
  end
@@ -19,6 +21,8 @@ module Kanal
19
21
  flow_batteries core
20
22
  attachments_batteries core
21
23
  keyboard_batteries core
24
+ username_batteries core
25
+ button_batteries core
22
26
  end
23
27
 
24
28
  def flow_batteries(core)
@@ -117,11 +121,95 @@ module Kanal
117
121
  def attachments_batteries(core)
118
122
  core.register_input_parameter :image
119
123
  core.register_input_parameter :audio
120
- core.register_input_parameter :file
124
+ core.register_input_parameter :video
125
+ core.register_input_parameter :document
121
126
 
122
127
  core.register_output_parameter :image
123
128
  core.register_output_parameter :audio
124
- core.register_output_parameter :file
129
+ core.register_output_parameter :video
130
+ core.register_output_parameter :document
131
+
132
+ _this = self
133
+
134
+ core.add_condition_pack :image do
135
+ add_condition :exists do
136
+ met? do |input, _core, _argument|
137
+ !input.image.nil?
138
+ end
139
+ end
140
+
141
+ add_condition :is do
142
+ with_argument
143
+
144
+ met? do |input, _, argument|
145
+ if input.image.image? && input.image.send((argument.to_s + "?").to_sym)
146
+ true
147
+ else
148
+ false
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ core.add_condition_pack :audio do
155
+ add_condition :exists do
156
+ met? do |input, _core, _argument|
157
+ !input.audio.nil?
158
+ end
159
+ end
160
+
161
+ add_condition :is do
162
+ with_argument
163
+
164
+ met? do |input, _, argument|
165
+ if input.audio.audio? && input.audio.send((argument.to_s + "?").to_sym)
166
+ true
167
+ else
168
+ false
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ core.add_condition_pack :video do
175
+ add_condition :exists do
176
+ met? do |input, _core, _argument|
177
+ !input.video.nil?
178
+ end
179
+ end
180
+
181
+ add_condition :is do
182
+ with_argument
183
+
184
+ met? do |input, _, argument|
185
+ if input.video.video? && input.video.send((argument.to_s + "?").to_sym)
186
+ true
187
+ else
188
+ false
189
+ end
190
+ end
191
+ end
192
+ end
193
+
194
+ core.add_condition_pack :document do
195
+ add_condition :exists do
196
+ met? do |input, _core, _argument|
197
+ !input.document.nil?
198
+ end
199
+ end
200
+
201
+ add_condition :is do
202
+ with_argument
203
+
204
+ met? do |input, _, argument|
205
+ if input.document.document? && input.document.send((argument.to_s + "?").to_sym)
206
+ true
207
+ else
208
+ false
209
+ end
210
+ end
211
+ end
212
+ end
125
213
  end
126
214
 
127
215
  def keyboard_batteries(core)
@@ -131,6 +219,24 @@ module Kanal
131
219
  output.keyboard = Keyboard.new
132
220
  end
133
221
  end
222
+
223
+ def username_batteries(core)
224
+ core.register_input_parameter :username
225
+ end
226
+
227
+ def button_batteries(core)
228
+ core.register_input_parameter :button_pressed
229
+
230
+ core.add_condition_pack :button do
231
+ add_condition :pressed do
232
+ with_argument
233
+
234
+ met? do |input, _, argument|
235
+ input.button_pressed == argument
236
+ end
237
+ end
238
+ end
239
+ end
134
240
  end
135
241
  end
136
242
  end
data/lib/kanal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanal
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.3"
5
5
  end
data/lib/kanal.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "kanal/version"
4
4
  require_relative "kanal/core/core"
5
5
  require_relative "kanal/core/plugins/plugin"
6
+ require_relative "shortcuts"
6
7
 
7
8
  # This module used as a main entry point into kanal-core library
8
9
  module Kanal
data/lib/shortcuts.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./kanal/core/logging/logger"
4
+
5
+ module Kanal
6
+ module Logger
7
+ include Kanal::Core::Logging::Logger
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - idchlife
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-22 00:00:00.000000000 Z
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Thanks to the core library, ecosystem of Kanal tools can be extendted
14
14
  to use with input-output bot-like behaviour, with routing
@@ -63,6 +63,7 @@ files:
63
63
  - lib/kanal/plugins/batteries/batteries_plugin.rb
64
64
  - lib/kanal/plugins/batteries/keyboard.rb
65
65
  - lib/kanal/version.rb
66
+ - lib/shortcuts.rb
66
67
  - sig/kanal.rbs
67
68
  - sig/kanal/core/conditions/condition_pack.rbs
68
69
  - sig/kanal/core/conditions/condition_storage.rbs