Class: Ruboty::Variable::Actions::ArrayPush
- Inherits:
-
Variable
- Object
- Actions::Base
- Variable
- Ruboty::Variable::Actions::ArrayPush
show all
- Defined in:
- lib/ruboty/variable/actions/array_push.rb
Instance Method Summary
collapse
Methods inherited from Variable
#initialize
Instance Method Details
#call(key, values) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 5
def call(key, values)
case var.type(key)
when 'array'
values.split(/\s+/).each {|value| push(key, value)}
when nil
message.reply(undefined_message(key))
else
message.reply(type_error_message(key))
end
end
|
#included_message(key, value) ⇒ Object
25
26
27
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 25
def included_message(key, value)
"#{key} already included #{value}"
end
|
#push(key, value) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 16
def push(key, value)
if var.array_include?(key, value)
message.reply(included_message(key, value))
else
var.array_push(key, value)
message.reply(push_message(key, value))
end
end
|
#push_message(key, value) ⇒ Object
29
30
31
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 29
def push_message(key, value)
"Push #{value} to #{key}"
end
|
#type_error_message(key) ⇒ Object
33
34
35
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 33
def type_error_message(key)
"#{key} is not array type"
end
|
#undefined_message(key) ⇒ Object
37
38
39
|
# File 'lib/ruboty/variable/actions/array_push.rb', line 37
def undefined_message(key)
"Undefined #{key}"
end
|