Class: TableStructure::Schema::ContextBuilders

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/schema/context_builders.rb

Instance Method Summary collapse

Constructor Details

#initialize(builders) ⇒ ContextBuilders

Returns a new instance of ContextBuilders.



6
7
8
9
10
# File 'lib/table_structure/schema/context_builders.rb', line 6

def initialize(builders)
  @table_builder = builders[:table]
  @header_builder = builders[:header]
  @row_builder = builders[:row]
end

Instance Method Details

#build_for_table(context) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/table_structure/schema/context_builders.rb', line 12

def build_for_table(context)
  if @table_builder
    @table_builder.call(context)
  else
    context
  end
end

#extend_methods_for(table) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/table_structure/schema/context_builders.rb', line 20

def extend_methods_for(table)
  methods = {}

  if table.send(:contain_callable?, :name)
    methods[:header] = create_method(@header_builder)
  end
  if table.send(:contain_callable?, :value)
    methods[:data] = create_method(@row_builder)
  end

  methods.reject! { |_k, v| v.nil? }
  return if methods.empty?

  table.extend ContextBuildable.new(methods)
end