Class: Proforma::Modeling::DataTable::Column

Inherits:
Object
  • Object
show all
Includes:
Compiling::Compilable, Types::Align
Defined in:
lib/proforma/modeling/data_table/column.rb

Overview

An explicit table column that understands how to compile header, body, and footer cells from records.

Constant Summary

Constants included from Types::Align

Types::Align::CENTER, Types::Align::LEFT, Types::Align::RIGHT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(align: LEFT, body: '', footer: '', header: '', width: nil) ⇒ Column

Returns a new instance of Column.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/proforma/modeling/data_table/column.rb', line 26

def initialize(
  align: LEFT,
  body: '',
  footer: '',
  header: '',
  width: nil
)
  @align  = align
  @body   = body
  @footer = footer
  @header = header
  @width  = width
end

Instance Attribute Details

#alignObject



40
41
42
# File 'lib/proforma/modeling/data_table/column.rb', line 40

def align
  @align || LEFT
end

#bodyObject



44
45
46
# File 'lib/proforma/modeling/data_table/column.rb', line 44

def body
  @body.to_s
end


48
49
50
# File 'lib/proforma/modeling/data_table/column.rb', line 48

def footer
  @footer.to_s
end

#headerObject



52
53
54
# File 'lib/proforma/modeling/data_table/column.rb', line 52

def header
  @header.to_s
end

#widthObject



56
57
58
# File 'lib/proforma/modeling/data_table/column.rb', line 56

def width
  @width ? @width.to_f : nil
end

Instance Method Details

#compile_body_cell(record, evaluator) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/proforma/modeling/data_table/column.rb', line 68

def compile_body_cell(record, evaluator)
  Modeling::Table::Cell.new(
    align: align,
    text: evaluator.text(record, body),
    width: width
  )
end


76
77
78
79
80
81
82
# File 'lib/proforma/modeling/data_table/column.rb', line 76

def compile_footer_cell(record, evaluator)
  Modeling::Table::Cell.new(
    align: align,
    text: evaluator.text(record, footer),
    width: width
  )
end

#compile_header_cell(record, evaluator) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/proforma/modeling/data_table/column.rb', line 60

def compile_header_cell(record, evaluator)
  Modeling::Table::Cell.new(
    align: align,
    text: evaluator.text(record, header),
    width: width
  )
end

#footer?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/proforma/modeling/data_table/column.rb', line 84

def footer?
  !footer.to_s.empty?
end

#header?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/proforma/modeling/data_table/column.rb', line 88

def header?
  !header.to_s.empty?
end