Class: TableHelp::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/table_help/strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, symbol_or_proc) ⇒ Strategy

Returns a new instance of Strategy.



5
6
7
8
# File 'lib/table_help/strategy.rb', line 5

def initialize(name, symbol_or_proc)
  @name = name
  @symbol_or_proc = symbol_or_proc
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/table_help/strategy.rb', line 3

def name
  @name
end

#symbol_or_procObject (readonly)

Returns the value of attribute symbol_or_proc.



3
4
5
# File 'lib/table_help/strategy.rb', line 3

def symbol_or_proc
  @symbol_or_proc
end

Instance Method Details

#to_value(record, context = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/table_help/strategy.rb', line 10

def to_value(record, context = nil)
  case symbol_or_proc
  when Symbol, String
    record.send(symbol_or_proc)
  when Proc
    context.capture { symbol_or_proc.call(record) }
  else
    record.send(name)
  end
end