Class: Cotcube::Indicators::Carrier

Inherits:
Object
  • Object
show all
Defined in:
lib/cotcube-indicators/__carrier.rb

Instance Method Summary collapse

Constructor Details

#initialize(length:) ⇒ Carrier

Returns a new instance of Carrier.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
# File 'lib/cotcube-indicators/__carrier.rb', line 6

def initialize(length:)
  raise ArgumentError, 'Need a length to be an integer' unless length.is_a? Integer

  @length = length
  @content = []
end

Instance Method Details

#<<(obj) ⇒ Object



13
14
15
16
17
# File 'lib/cotcube-indicators/__carrier.rb', line 13

def <<(obj)
  @content << obj
  @content.shift if @content.length > @length
  obj
end

#[](key) ⇒ Object



42
43
44
# File 'lib/cotcube-indicators/__carrier.rb', line 42

def [](key)
  @content.map { |x| x[key] }
end

#clearObject



25
26
27
# File 'lib/cotcube-indicators/__carrier.rb', line 25

def clear
  @content = []
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/cotcube-indicators/__carrier.rb', line 38

def empty?
  @content.empty?
end

#getObject



29
30
31
# File 'lib/cotcube-indicators/__carrier.rb', line 29

def get
  @content
end

#shiftObject



19
20
21
22
23
# File 'lib/cotcube-indicators/__carrier.rb', line 19

def shift
  @content.shift
  # sending explicit return to avoid returning a value here
  nil
end

#sizeObject Also known as: length



33
34
35
# File 'lib/cotcube-indicators/__carrier.rb', line 33

def size
  @content.size
end