Class: Repim::AxAttributeAdapter
- Inherits:
-
Object
- Object
- Repim::AxAttributeAdapter
- Defined in:
- lib/repim/ax_attributes_adapter.rb
Instance Attribute Summary collapse
-
#necessity ⇒ Object
readonly
Returns the value of attribute necessity.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #adapt(fetched) ⇒ Object
-
#initialize(prefixes, propaties) ⇒ AxAttributeAdapter
constructor
TODO refactor.
- #keys ⇒ Object
- #required! ⇒ Object
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
#necessity ⇒ Object (readonly)
Returns the value of attribute necessity.
5 6 7 |
# File 'lib/repim/ax_attributes_adapter.rb', line 5 def necessity @necessity end |
#rule ⇒ Object (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 |
#keys ⇒ Object
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 |