Class: ChatScript::Message

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = '', oob: '') ⇒ Message

Returns a new instance of Message.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/chatscript.rb', line 13

def initialize(text = '', oob: '')
  if text.match(/\[.*\]/).nil?
    # no oob inside txt
    @text = text.strip
    @oob = oob
  else   
    # split oob from txt 
    @oob, @text = text.match(/\[(.*)\](.*)/).captures
    
    # remove any blanks
    @text.strip!
    @oob.strip!
  end
end

Instance Attribute Details

#oobObject

Returns the value of attribute oob.



11
12
13
# File 'lib/chatscript.rb', line 11

def oob
  @oob
end

#textObject

Returns the value of attribute text.



11
12
13
# File 'lib/chatscript.rb', line 11

def text
  @text
end

Instance Method Details

#command?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/chatscript.rb', line 28

def command?
  @text.start_with? ':'
end

#to_strObject



32
33
34
# File 'lib/chatscript.rb', line 32

def to_str
  @oob.empty? ? @text : "[ #@oob ] #@text"
end