Class: Slamdown::Conversion::Tables::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/slamdown/conversion/tables.rb

Overview

Holds one format-specific grouping of a format-neutral source table after the shared grid algorithm has run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head_rows, body_groups, foot_rows) ⇒ Layout

Returns a new instance of Layout.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/slamdown/conversion/tables.rb', line 62

def initialize(head_rows, body_groups, foot_rows)
	@ragged_padded = false
	rows = head_rows + body_groups.flatten + foot_rows
	if rows.length > MAX_ROWS
		set_limited(:row_count)
		return
	end

	expanded_by_row, @complexity_reason = expand(rows)
	if complexity_limited?
		set_empty_groups
		freeze
		return
	end
	expanded_by_row, @ragged_padded, padding_error = pad_ragged_rows(rows, expanded_by_row)
	if padding_error
		set_limited(padding_error)
		return
	end
	@head_rows = map_rows(head_rows, expanded_by_row)
	@body_groups = body_groups.map { |group| map_rows(group, expanded_by_row) }.freeze
	@foot_rows = map_rows(foot_rows, expanded_by_row)
	@expanded_by_node_id = rows.each_with_object({}) { |row, result| result[row.node.object_id] = expanded_by_row.fetch(row.object_id) }.freeze
	freeze
end

Instance Attribute Details

#body_groupsObject (readonly)

Returns the value of attribute body_groups.



60
61
62
# File 'lib/slamdown/conversion/tables.rb', line 60

def body_groups
  @body_groups
end

#complexity_reasonObject (readonly)

Returns the value of attribute complexity_reason.



60
61
62
# File 'lib/slamdown/conversion/tables.rb', line 60

def complexity_reason
  @complexity_reason
end

#foot_rowsObject (readonly)

Returns the value of attribute foot_rows.



60
61
62
# File 'lib/slamdown/conversion/tables.rb', line 60

def foot_rows
  @foot_rows
end

#head_rowsObject (readonly)

Returns the value of attribute head_rows.



60
61
62
# File 'lib/slamdown/conversion/tables.rb', line 60

def head_rows
  @head_rows
end

Instance Method Details

#complexity_limited?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/slamdown/conversion/tables.rb', line 97

def complexity_limited?
	!complexity_reason.nil?
end

#expanded_row(node) ⇒ Object



105
106
107
# File 'lib/slamdown/conversion/tables.rb', line 105

def expanded_row(node)
	@expanded_by_node_id[node.object_id]
end

#ragged_padded?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/slamdown/conversion/tables.rb', line 101

def ragged_padded?
	@ragged_padded
end

#rectangular?Boolean

Returns:

  • (Boolean)


92
93
94
95
# File 'lib/slamdown/conversion/tables.rb', line 92

def rectangular?
	widths = rows.map(&:length)
	!widths.empty? && widths.first > 0 && widths.uniq.length == 1 && rows.none? { |row| row.any?(&:nil?) }
end

#rowsObject



88
89
90
# File 'lib/slamdown/conversion/tables.rb', line 88

def rows
	head_rows + body_groups.inject([]) { |result, group| result + group } + foot_rows
end