Class: AdvAccessor::Mappings

Inherits:
BaseReaders show all
Defined in:
lib/adv_accessor/mapping.rb

Instance Attribute Summary

Attributes inherited from BaseReaders

#base

Instance Method Summary collapse

Methods inherited from BaseReaders

#<<

Instance Method Details

#add(ops, &b) ⇒ Object



41
42
43
44
45
# File 'lib/adv_accessor/mapping.rb', line 41

def add(ops,&b)
  ops.each do |from,to|
    self << Mapping.new(:from => from, :to => to, :block => b, :base => self)
  end
end

#get(arg) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/adv_accessor/mapping.rb', line 46

def get(arg)
  arg = {:from => base.value.class, :to => arg} unless arg.kind_of?(Hash)
  arg[:from] ||= base.value.class
  if act_on_array && base.value.kind_of?(Array)
    base.value.map do |val|
      super(arg.merge(:val => val))
    end
  else
    super(arg)
  end
end