Class: AppdirectIntegration::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/appdirect_integration/util.rb

Class Method Summary collapse

Class Method Details

.copy_data(to, field_name, val) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/appdirect_integration/util.rb', line 33

def self.copy_data(to, field_name, val)
  method_name = field_name + '='
  method_sym = method_name.to_sym
  if val.present? && to.respond_to?(method_name)
    to.send(method_sym, val)
  end
end

.copy_known_fields(to, from) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/appdirect_integration/util.rb', line 6

def self.copy_known_fields(to, from)
  AppdirectIntegration::FIELDS.each do |field|
    if field[:path].present?
      Util.copy_path(to, field[:name], from, field[:path])
    end
  end
  to
end

.copy_path(to, field_name, from, path) ⇒ Object

path here is the array with size >= 1



16
17
18
19
# File 'lib/appdirect_integration/util.rb', line 16

def self.copy_path(to, field_name, from, path)
  val = Util.val_by_path(from, path)
  Util.copy_data(to, field_name, val)
end

.val_by_path(from, path) ⇒ Object

path here is the array with size >= 1



22
23
24
25
26
27
28
29
30
31
# File 'lib/appdirect_integration/util.rb', line 22

def self.val_by_path(from, path)
  val = from
  path.each do |index|
    val = val[index]
    if val.nil?
      return val
    end
  end
  val
end