Class: Ruboty::Variable::Actions::ArrayRemove
- Inherits:
-
Variable
- Object
- Actions::Base
- Variable
- Ruboty::Variable::Actions::ArrayRemove
show all
- Defined in:
- lib/ruboty/variable/actions/array_remove.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_remove.rb', line 5
def call(key, values)
case var.type(key)
when 'array'
values.split(/\s+/).each {|value| remove(key, value)}
when nil
message.reply(undefined_message(key))
else
message.reply(type_error_message(key))
end
end
|
#not_found_message(key, value) ⇒ Object
29
30
31
|
# File 'lib/ruboty/variable/actions/array_remove.rb', line 29
def not_found_message(key, value)
"#{value} is not found in #{key}"
end
|
#remove(key, value) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/ruboty/variable/actions/array_remove.rb', line 16
def remove(key, value)
if var.array_include?(key, value)
var.array_remove(key, value)
message.reply(remove_message(key, value))
else
message.reply(not_found_message(key, value))
end
end
|
#remove_message(key, value) ⇒ Object
25
26
27
|
# File 'lib/ruboty/variable/actions/array_remove.rb', line 25
def remove_message(key, value)
"Remove #{value} from #{key}"
end
|
#type_error_message(key) ⇒ Object
33
34
35
|
# File 'lib/ruboty/variable/actions/array_remove.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_remove.rb', line 37
def undefined_message(key)
"Undefined #{key}"
end
|