Class: Chunks::ChunkLine

Inherits:
Object show all
Defined in:
lib/rbcurse/core/include/chunk.rb

Overview

consists of an array of chunks and corresponds to a line to be printed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr = nil) ⇒ ChunkLine

Returns a new instance of ChunkLine.



45
46
47
# File 'lib/rbcurse/core/include/chunk.rb', line 45

def initialize arr=nil
  @chunks = arr.nil? ? Array.new : arr
end

Instance Attribute Details

#chunksObject (readonly)

an array of chunks



43
44
45
# File 'lib/rbcurse/core/include/chunk.rb', line 43

def chunks
  @chunks
end

Instance Method Details

#<<(chunk) ⇒ Object Also known as: add

Raises:

  • (ArgumentError)


48
49
50
51
# File 'lib/rbcurse/core/include/chunk.rb', line 48

def <<(chunk)
  raise ArgumentError, "Chunk object expected. Received #{chunk.class} " unless chunk.is_a? Chunk
  @chunks << chunk
end

#each(&block) ⇒ Object



53
54
55
# File 'lib/rbcurse/core/include/chunk.rb', line 53

def each &block
  @chunks.each &block
end

#row_lengthObject Also known as: length, size

returns length of text in chunks



58
59
60
61
62
# File 'lib/rbcurse/core/include/chunk.rb', line 58

def row_length
  result = 0
  @chunks.each { |e| result += e.text.length }
  return result
end

#substring(start, size) ⇒ Object

return a Chunkline containing only the text for the range requested



67
68
# File 'lib/rbcurse/core/include/chunk.rb', line 67

def substring start, size
end

#to_sObject



69
70
71
72
73
# File 'lib/rbcurse/core/include/chunk.rb', line 69

def to_s
  result = ""
  @chunks.each { |e| result << e.text }
  result
end