Class: Arrolio::ColumnSet

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/column_set.rb

Overview

A multi-column frame that splits a region's width into N equal columns. The engine flows content column-by-column: when one column overflows, content moves to the next column; when all columns overflow, the page breaks. This is the foundation for multi-column body text (e.g., 2-column technical specs).

Usage in layout spec YAML:

page_templates:
body:
  columns: 2
  column_gap: 6mm

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_count:, gap:, total_width:, total_height:) ⇒ ColumnSet

Returns a new instance of ColumnSet.



18
19
20
21
22
23
24
# File 'lib/arrolio/column_set.rb', line 18

def initialize(column_count:, gap:, total_width:, total_height:)
  @column_count = column_count.to_i
  @gap = gap.to_f
  @total_width = total_width.to_f
  @total_height = total_height.to_f
  freeze
end

Instance Attribute Details

#column_countObject (readonly)

Returns the value of attribute column_count.



16
17
18
# File 'lib/arrolio/column_set.rb', line 16

def column_count
  @column_count
end

#gapObject (readonly)

Returns the value of attribute gap.



16
17
18
# File 'lib/arrolio/column_set.rb', line 16

def gap
  @gap
end

#total_heightObject (readonly)

Returns the value of attribute total_height.



16
17
18
# File 'lib/arrolio/column_set.rb', line 16

def total_height
  @total_height
end

#total_widthObject (readonly)

Returns the value of attribute total_width.



16
17
18
# File 'lib/arrolio/column_set.rb', line 16

def total_width
  @total_width
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



51
52
53
54
55
56
57
# File 'lib/arrolio/column_set.rb', line 51

def ==(other)
  other.is_a?(self.class) &&
    column_count == other.column_count &&
    gap == other.gap &&
    total_width == other.total_width &&
    total_height == other.total_height
end

#column_widthObject

Width of a single column (total - gaps) / count.



27
28
29
30
31
# File 'lib/arrolio/column_set.rb', line 27

def column_width
  return @total_width if @column_count <= 1

  (@total_width - (@gap * (@column_count - 1))) / @column_count
end

#column_x(index) ⇒ Object

X position of column at index (0-based).



34
35
36
37
38
# File 'lib/arrolio/column_set.rb', line 34

def column_x(index)
  return 0.0 if @column_count <= 1

  index * (column_width + @gap)
end

#each_columnObject

Enumerate each column as a [x, width] pair.



41
42
43
44
45
# File 'lib/arrolio/column_set.rb', line 41

def each_column
  return enum_for(:each_column) unless block_given?

  @column_count.times { |i| yield(column_x(i), column_width) }
end

#hashObject



60
61
62
# File 'lib/arrolio/column_set.rb', line 60

def hash
  [self.class, column_count, gap, total_width, total_height].hash
end

#single_column?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/arrolio/column_set.rb', line 47

def single_column?
  @column_count <= 1
end