Class: Tablemaker::Node

Inherits:
Frame
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tablemaker/frame.rb

Direct Known Subclasses

Column, Row

Instance Attribute Summary collapse

Attributes inherited from Frame

#parent

Instance Method Summary collapse

Methods inherited from Frame

#dimensions, #last?, #real_cols, #real_dimensions, #real_rows

Constructor Details

#initialize(p = nil, idx = nil) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



61
62
63
64
65
# File 'lib/tablemaker/frame.rb', line 61

def initialize(p=nil, idx = nil)
  super
  @items = []
  yield self
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



58
59
60
# File 'lib/tablemaker/frame.rb', line 58

def items
  @items
end

Instance Method Details

#cell(*args) ⇒ Object



67
68
69
# File 'lib/tablemaker/frame.rb', line 67

def cell(*args)
  Cell.new(self, @items.length, *args).tap { |c| @items << c }
end

#cellsObject



71
72
73
74
75
76
77
78
79
# File 'lib/tablemaker/frame.rb', line 71

def cells
  f = Fiber.new do
    cell_iterator do |i|
      yield i
    end
    nil
  end
  f = f.resume while f && f.alive?
end

#each_rowObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/tablemaker/frame.rb', line 81

def each_row
  items = []
  f = Fiber.new do
    cell_iterator do |i|
      items << i
    end
    nil
  end

  while f && f.alive?
    f = f.resume
    yield items unless items.empty?
    items = []
  end
end