Class: Repim::AxAttributeAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/repim/ax_attributes_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefixes, propaties) ⇒ AxAttributeAdapter

TODO refactor



8
9
10
11
12
13
14
# File 'lib/repim/ax_attributes_adapter.rb', line 8

def initialize(prefixes, propaties)
  @rule = {}
  @necessity = :optional
  propaties.each do |model_attr, property|
    @rule[model_attr] = prefixes.map{|px| px + property }
  end
end

Instance Attribute Details

#necessityObject (readonly)

Returns the value of attribute necessity.



5
6
7
# File 'lib/repim/ax_attributes_adapter.rb', line 5

def necessity
  @necessity
end

#ruleObject (readonly)

Returns the value of attribute rule.



5
6
7
# File 'lib/repim/ax_attributes_adapter.rb', line 5

def rule
  @rule
end

Instance Method Details

#adapt(fetched) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/repim/ax_attributes_adapter.rb', line 24

def adapt(fetched)
  returning({}) do |res|
    rule.each do |k, vs|
      fetched.each{|fk, (fv,_)| res[k] = fv if !fv.blank? && vs.include?(fk) }
    end
  end
end

#keysObject



16
17
18
# File 'lib/repim/ax_attributes_adapter.rb', line 16

def keys
  rule.values.flatten
end

#required!Object



20
21
22
# File 'lib/repim/ax_attributes_adapter.rb', line 20

def required!
  @necessity = :required
end