Class: Ruboty::Variable::Variable

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/variable.rb

Constant Summary collapse

NAMESPACE =
'variable'

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Variable

Returns a new instance of Variable.



9
10
11
# File 'lib/ruboty/variable.rb', line 9

def initialize(message)
  @values = message.robot.brain.data[NAMESPACE] ||= {}
end

Instance Method Details

#array_include?(key, value) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruboty/variable.rb', line 43

def array_include?(key, value)
  values[key][:value].include?(value) if type(key) == 'array'
end

#array_init(key) ⇒ Object



28
29
30
31
32
33
# File 'lib/ruboty/variable.rb', line 28

def array_init(key)
  values[key] = {
      :type => 'array',
      :value => []
  }
end

#array_push(key, value) ⇒ Object



35
36
37
# File 'lib/ruboty/variable.rb', line 35

def array_push(key, value)
  values[key][:value] << value unless array_include?(key, value)
end

#array_remove(key, value) ⇒ Object



39
40
41
# File 'lib/ruboty/variable.rb', line 39

def array_remove(key, value)
  values[key][:value].delete(value) if array_include?(key, value)
end

#get(key) ⇒ Object



20
21
22
# File 'lib/ruboty/variable.rb', line 20

def get(key)
  values[key][:value] if values.has_key?(key)
end

#set(key, value) ⇒ Object



13
14
15
16
17
18
# File 'lib/ruboty/variable.rb', line 13

def set(key, value)
  values[key] = {
      :type => 'string',
      :value => value
  }
end

#type(key) ⇒ Object



24
25
26
# File 'lib/ruboty/variable.rb', line 24

def type(key)
  values[key][:type] if values.has_key?(key)
end

#valuesObject



47
48
49
# File 'lib/ruboty/variable.rb', line 47

def values
  @values
end