Class: RubyCurses::Chunks::ChunkLine

Inherits:
Object
  • 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.



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

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

added to take care of many string methods that are called. Callers really don’t know this is a chunkline, they assume its a string 2013-03-21 - 19:01



91
92
93
# File 'lib/rbcurse/core/include/chunk.rb', line 91

def method_missing(sym, *args, &block)
  self.to_s.send sym, *args, &block
end

Instance Attribute Details

#chunksObject (readonly)

an array of chunks



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

def chunks
  @chunks
end

Instance Method Details

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

Raises:

  • (ArgumentError)


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

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

#each(&block) ⇒ Object



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

def each &block
  @chunks.each &block
end

#index(str) ⇒ Object

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



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

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



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

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



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

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

#to_sObject



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

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