Class: Tabl::Table::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/tabl/table.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, table, base) ⇒ Format

Returns a new instance of Format.



80
81
82
83
84
# File 'lib/tabl/table.rb', line 80

def initialize(name, table, base)
  @name = name
  @table = table
  @base = base
end

Instance Method Details

#format(key, value, record) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/tabl/table.rb', line 97

def format(key, value, record)
  column = @table.column(key)

  if column.formats[@name]
    column.format(@name, value, record)
  else
    @base.format(value)
  end
end

#values(record) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/tabl/table.rb', line 86

def values(record)
  @table.keys.map do |key|
    value = @table.value(key, record)
    if value
      format(key, value, record)
    else
      @base.default_value
    end
  end
end