Class: Charty::GridLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/charty/layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_cols, num_rows) ⇒ GridLayout

Returns a new instance of GridLayout


63
64
65
66
67
68
# File 'lib/charty/layout.rb', line 63

def initialize(num_cols, num_rows)
  @rows = Array.new(num_rows) { Array.new(num_cols) }
  @num_cols = num_cols
  @num_rows = num_rows
  @cursor = 0
end

Instance Attribute Details

#num_colsObject (readonly)

Returns the value of attribute num_cols


61
62
63
# File 'lib/charty/layout.rb', line 61

def num_cols
  @num_cols
end

#num_rowsObject (readonly)

Returns the value of attribute num_rows


61
62
63
# File 'lib/charty/layout.rb', line 61

def num_rows
  @num_rows
end

#rowsObject (readonly)

Returns the value of attribute rows


61
62
63
# File 'lib/charty/layout.rb', line 61

def rows
  @rows
end

Instance Method Details

#<<(content) ⇒ Object


70
71
72
73
# File 'lib/charty/layout.rb', line 70

def <<(content)
  @rows[@cursor / @num_rows][@cursor % @num_cols] = content
  @cursor += 1
end