Class: Tabl::DerefColumn

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column, deref) ⇒ DerefColumn

Returns a new instance of DerefColumn.



5
6
7
8
9
10
# File 'lib/tabl/deref_column.rb', line 5

def initialize(column, deref)
  @column = column
  @callback = deref
  @callback = lambda { |record| record.send(deref) } if Symbol === deref
  @format_dsl = Column::FormatDsl.new(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



29
30
31
# File 'lib/tabl/deref_column.rb', line 29

def method_missing(name, *args)
  @column.send(name, *args)
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



3
4
5
# File 'lib/tabl/deref_column.rb', line 3

def column
  @column
end

Instance Method Details

#cloneObject



33
34
35
# File 'lib/tabl/deref_column.rb', line 33

def clone
  DerefColumn.new(@column.clone, @callback.clone)
end

#deref(record) ⇒ Object



25
26
27
# File 'lib/tabl/deref_column.rb', line 25

def deref(record)
  @callback.call(record)
end

#format(format = nil, value = nil, record = nil, context = nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/tabl/deref_column.rb', line 16

def format(format = nil, value = nil, record = nil, context = nil)
  if format.nil?
    @format_dsl
  else
    record = deref(record) if record
    @column.format(format, value, record, context)
  end
end

#value(record) ⇒ Object



12
13
14
# File 'lib/tabl/deref_column.rb', line 12

def value(record)
  @column.value(deref(record))
end