Class: Rentlinx::AttributeProcessor
- Inherits:
-
Object
- Object
- Rentlinx::AttributeProcessor
- Defined in:
- lib/rentlinx/validators/attribute_processor_service.rb
Overview
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#processed_attrs ⇒ Object
readonly
Returns the value of attribute processed_attrs.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ AttributeProcessor
constructor
A new instance of AttributeProcessor.
-
#process ⇒ Object
Processes the attributes, both validating them and processing them into a format suitable for Rentlinx.
-
#valid? ⇒ Boolean
Determines the validity of the attributes it contains.
Constructor Details
#initialize(attrs) ⇒ AttributeProcessor
Returns a new instance of AttributeProcessor.
18 19 20 21 22 |
# File 'lib/rentlinx/validators/attribute_processor_service.rb', line 18 def initialize(attrs) @attrs = attrs @processed_attrs = @attrs @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
14 15 16 |
# File 'lib/rentlinx/validators/attribute_processor_service.rb', line 14 def errors @errors end |
#processed_attrs ⇒ Object (readonly)
Returns the value of attribute processed_attrs.
15 16 17 |
# File 'lib/rentlinx/validators/attribute_processor_service.rb', line 15 def processed_attrs @processed_attrs end |
Instance Method Details
#process ⇒ Object
Processes the attributes, both validating them and processing them into a format suitable for Rentlinx.
This method also populates the errors attribute, so it must be run before calling .valid? or querying for errors.
Currently, phone number, state, zip, and leads URL are validated. They are passed into their own validator objects: PhoneValidator, StateValidator, ZipValidator, and UrlValidator
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rentlinx/validators/attribute_processor_service.rb', line 35 def process validators = { phoneNumber: PhoneValidator, state: StateValidator, zip: ZipValidator, leadsURL: UrlValidator, city: CityValidator, address: AddressValidator, capAmount: AmountValidator, companyCapAmount: AmountValidator } @attrs.each do |field, val| next unless validators.keys.include?(field) validator = validators[field].new(val) @processed_attrs[field] = validator.processed_value @errors[field] = validator.error unless validator.valid? end @processed_attrs end |
#valid? ⇒ Boolean
Determines the validity of the attributes it contains.
58 59 60 |
# File 'lib/rentlinx/validators/attribute_processor_service.rb', line 58 def valid? @errors.empty? end |