Class: Ambo::State

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ambo/state.rb

Overview

Class for managing each bot's state

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State


10
11
12
13
# File 'lib/ambo/state.rb', line 10

def initialize
  @history = []
  @history_size = 1
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history


8
9
10
# File 'lib/ambo/state.rb', line 8

def history
  @history
end

Instance Method Details

#<<(msg_txt) ⇒ Object


21
22
23
24
25
26
# File 'lib/ambo/state.rb', line 21

def <<(msg_txt)
  @history.unshift time: Time.now, message: msg_txt
  @history.pop while @history.size > @history_size

  self
end

#<=>(other) ⇒ Object


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

def <=>(other)
  @history <=> other.history
end

#last_sentObject


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

def last_sent
  @history.first&.fetch(:time)
end

#update(ctx) ⇒ Object


15
16
17
18
19
# File 'lib/ambo/state.rb', line 15

def update(ctx)
  @history_size = ctx.config.every&.fetch(:repeat_after, 1) || 1

  self
end