Class: DiscordRDA::MessageIterator
- Inherits:
-
Object
- Object
- DiscordRDA::MessageIterator
- Includes:
- Enumerable
- Defined in:
- lib/discord_rda/entity/channel.rb
Overview
Iterator for paginating through channel messages
Instance Attribute Summary collapse
-
#batch_size ⇒ Integer
readonly
Messages per batch.
-
#channel ⇒ Channel
readonly
Channel being iterated.
-
#direction ⇒ Symbol
readonly
Direction (:backwards or :forwards).
Instance Method Summary collapse
-
#each {|Message| ... } ⇒ Object
Iterate over all messages.
-
#initialize(channel, batch_size: 100, direction: :backwards) ⇒ MessageIterator
constructor
Initialize iterator.
-
#more? ⇒ Boolean
Check if there are more messages.
-
#next ⇒ Message?
Get next message.
-
#reset ⇒ self
Reset the iterator.
Constructor Details
#initialize(channel, batch_size: 100, direction: :backwards) ⇒ MessageIterator
Initialize iterator
381 382 383 384 385 386 387 388 |
# File 'lib/discord_rda/entity/channel.rb', line 381 def initialize(channel, batch_size: 100, direction: :backwards) @channel = channel @batch_size = batch_size @direction = direction @last_id = nil @buffer = [] @exhausted = false end |
Instance Attribute Details
#batch_size ⇒ Integer (readonly)
Returns Messages per batch.
372 373 374 |
# File 'lib/discord_rda/entity/channel.rb', line 372 def batch_size @batch_size end |
#channel ⇒ Channel (readonly)
Returns Channel being iterated.
369 370 371 |
# File 'lib/discord_rda/entity/channel.rb', line 369 def channel @channel end |
#direction ⇒ Symbol (readonly)
Returns Direction (:backwards or :forwards).
375 376 377 |
# File 'lib/discord_rda/entity/channel.rb', line 375 def direction @direction end |
Instance Method Details
#each {|Message| ... } ⇒ Object
Iterate over all messages
406 407 408 409 410 411 412 413 414 415 |
# File 'lib/discord_rda/entity/channel.rb', line 406 def each return to_enum unless block_given? loop do = self.next break unless yield end end |
#more? ⇒ Boolean
Check if there are more messages
400 401 402 |
# File 'lib/discord_rda/entity/channel.rb', line 400 def more? !@exhausted || !@buffer.empty? end |
#next ⇒ Message?
Get next message
392 393 394 395 396 |
# File 'lib/discord_rda/entity/channel.rb', line 392 def next fill_buffer if @buffer.empty? && !@exhausted @buffer.shift end |
#reset ⇒ self
Reset the iterator
419 420 421 422 423 424 |
# File 'lib/discord_rda/entity/channel.rb', line 419 def reset @last_id = nil @buffer = [] @exhausted = false self end |