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

#index(str) ⇒ Object

returns match for str in this chunk added 2013-03-07 - 23:59



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

def index str
  result = 0
  @chunks.each { |e| txt = e.text; 
    ix =  txt.index(str) 
    return result + ix if ix
    result += e.text.length 
  }
  return nil
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



78
79
80
# File 'lib/rbcurse/core/include/chunk.rb', line 78

def substring start, size
  raise "substring not implemented yet"
end

#to_sObject



81
82
83
84
85
# File 'lib/rbcurse/core/include/chunk.rb', line 81

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