Class: Tabulo::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/tabulo/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Column

Returns a new instance of Column.



7
8
9
10
11
12
13
14
# File 'lib/tabulo/column.rb', line 7

def initialize(options)
  @label, @header = options[:label], options[:header]
  @truncate = options[:truncate]
  @align_header, @align_body = options[:align_header], options[:align_body]
  @extractor, @formatter = options[:extractor], options[:formatter]
  @width = options[:width]
  @horizontal_rule_character = options[:horizontal_rule_character]
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/tabulo/column.rb', line 5

def label
  @label
end

#truncateObject (readonly)

Returns the value of attribute truncate.



5
6
7
# File 'lib/tabulo/column.rb', line 5

def truncate
  @truncate
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/tabulo/column.rb', line 5

def width
  @width
end

Instance Method Details

#body_cell(source) ⇒ Object



24
25
26
27
28
29
# File 'lib/tabulo/column.rb', line 24

def body_cell(source)
  cell_datum = body_cell_value(source)
  formatted_cell_content = @formatter.call(cell_datum)
  real_alignment = @align_body || infer_alignment(cell_datum)
  align_cell_content(formatted_cell_content, real_alignment)
end

#body_cell_value(source) ⇒ Object



31
32
33
# File 'lib/tabulo/column.rb', line 31

def body_cell_value(source)
  @extractor.call(source)
end

#header_cellObject



16
17
18
# File 'lib/tabulo/column.rb', line 16

def header_cell
  align_cell_content(@header, @align_header)
end

#horizontal_ruleObject



20
21
22
# File 'lib/tabulo/column.rb', line 20

def horizontal_rule
  @horizontal_rule_character * @width
end