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, context) ⇒ Object



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

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

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

#values(record, context = nil) ⇒ Object



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

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