Class: Chunks::ChunkLine
Overview
consists of an array of chunks and corresponds to a line to be printed.
Instance Attribute Summary collapse
-
#chunks ⇒ Object
readonly
an array of chunks.
Instance Method Summary collapse
- #<<(chunk) ⇒ Object (also: #add)
- #each(&block) ⇒ Object
-
#initialize(arr = nil) ⇒ ChunkLine
constructor
A new instance of ChunkLine.
-
#row_length ⇒ Object
(also: #length, #size)
returns length of text in chunks.
-
#substring(start, size) ⇒ Object
return a Chunkline containing only the text for the range requested.
- #to_s ⇒ Object
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
#chunks ⇒ Object (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
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_length ⇒ Object 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_s ⇒ Object
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 |