Class: TableStructure::Schema::ColumnBuilderFactory
- Inherits:
-
Object
- Object
- TableStructure::Schema::ColumnBuilderFactory
- Defined in:
- lib/table_structure/schema/column_builder_factory.rb
Instance Method Summary collapse
- #create_data_builder ⇒ Object
- #create_header_builder ⇒ Object
-
#initialize(builders, context: nil, name_prefix: nil, name_suffix: nil) ⇒ ColumnBuilderFactory
constructor
A new instance of ColumnBuilderFactory.
Constructor Details
#initialize(builders, context: nil, name_prefix: nil, name_suffix: nil) ⇒ ColumnBuilderFactory
Returns a new instance of ColumnBuilderFactory.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/table_structure/schema/column_builder_factory.rb', line 6 def initialize( builders, context: nil, name_prefix: nil, name_suffix: nil ) @builders = builders @context = context optional_builders = {} if name_prefix optional_builders[:_name_prepender_] = ::TableStructure::Utils::TypedProc.new( types: :header ) do |val| val.nil? ? val : "#{name_prefix}#{val}" end end if name_suffix optional_builders[:_name_appender_] = ::TableStructure::Utils::TypedProc.new( types: :header ) do |val| val.nil? ? val : "#{val}#{name_suffix}" end end @builders.merge!(optional_builders) unless optional_builders.empty? end |
Instance Method Details
#create_data_builder ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/table_structure/schema/column_builder_factory.rb', line 56 def create_data_builder builders = @builders .select { |_k, v| v.typed?(:body) } .values return if builders.empty? proc do |row| row.values = row.values.map do |value| builders.reduce(value) do |value, builder| builder.call(value, row.context, @context) end end row end end |
#create_header_builder ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/table_structure/schema/column_builder_factory.rb', line 38 def create_header_builder builders = @builders .select { |_k, v| v.typed?(:header) } .values return if builders.empty? proc do |row| row.values = row.values.map do |value| builders.reduce(value) do |value, builder| builder.call(value, row.context, @context) end end row end end |