Class: Calibrate::Configurable::FieldProcessor
- Inherits:
-
Object
- Object
- Calibrate::Configurable::FieldProcessor
- Defined in:
- lib/calibrate/configurable/field-processor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field_names ⇒ Object
Returns the value of attribute field_names.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #can_process(field, target) ⇒ Object
- #filter(field_names) ⇒ Object
-
#initialize(source) ⇒ FieldProcessor
constructor
A new instance of FieldProcessor.
- #to(target) ⇒ Object
Constructor Details
#initialize(source) ⇒ FieldProcessor
Returns a new instance of FieldProcessor.
4 5 6 7 |
# File 'lib/calibrate/configurable/field-processor.rb', line 4 def initialize(source) @source = source @field_names = filter(source.class.field_names) end |
Instance Attribute Details
#field_names ⇒ Object
Returns the value of attribute field_names.
8 9 10 |
# File 'lib/calibrate/configurable/field-processor.rb', line 8 def field_names @field_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/calibrate/configurable/field-processor.rb', line 9 def source @source end |
Instance Method Details
#can_process(field, target) ⇒ Object
17 18 19 |
# File 'lib/calibrate/configurable/field-processor.rb', line 17 def can_process(field, target) target.respond_to?(field.writer_method) end |
#filter(field_names) ⇒ Object
11 12 13 14 15 |
# File 'lib/calibrate/configurable/field-processor.rb', line 11 def filter(field_names) field_names.find_all do |name| source.class.(name).is?(filter_attribute) end end |
#to(target) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/calibrate/configurable/field-processor.rb', line 21 def to(target) field_names.each do |name| field = source.class.(name) next unless can_process(field, target) target.__send__(field.writer_method, value(field)) end end |