Class: DataMaps::Dsl::Mapping::FieldMappingDsl

Inherits:
Struct
  • Object
show all
Includes:
Concerns::Configurable
Defined in:
lib/data_maps/dsl/mapping/field_dsl.rb

Overview

Structure to describe a field mapping

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Configurable

#configure

Constructor Details

#initialize(options = {}) ⇒ FieldMappingDsl

Returns a new instance of FieldMappingDsl.



8
9
10
11
12
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 8

def initialize(options = {})
  self.from = options[:from]
  self.conditions = []
  self.converter = []
end

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions

Returns:

  • (Object)

    the current value of conditions



5
6
7
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 5

def conditions
  @conditions
end

#converterObject

Returns the value of attribute converter

Returns:

  • (Object)

    the current value of converter



5
6
7
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 5

def converter
  @converter
end

#fromObject

Returns the value of attribute from

Returns:

  • (Object)

    the current value of from



5
6
7
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 5

def from
  @from
end

Instance Method Details

#condition(&block) ⇒ Object



14
15
16
17
18
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 14

def condition(&block)
  dsl = DataMaps::Dsl::Mapping::ConditionsDsl.new
  dsl.configure(&block) if block_given?
  self.conditions << dsl.to_h
end

#convert(converter, options = nil) ⇒ Object



20
21
22
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 20

def convert(converter, options = nil)
  self.converter << { apply: converter, option: options }
end

#to_hObject

Serialize DSL to an Hash



25
26
27
28
29
# File 'lib/data_maps/dsl/mapping/field_dsl.rb', line 25

def to_h
  data = super
  data[:convert] = data.delete(:converter)
  data.stringify_keys
end