Class: AdfBuilder::Nodes::Address
- Defined in:
- lib/adf_builder/nodes/shared.rb
Instance Attribute Summary
Attributes inherited from Node
#attributes, #children, #tag_name, #value
Instance Method Summary collapse
-
#initialize(type: nil) ⇒ Address
constructor
A new instance of Address.
- #street(value, line: nil) ⇒ Object
- #validate! ⇒ Object
Methods inherited from Node
#add_child, #method_missing, #remove_children, #respond_to_missing?, #to_xml
Methods included from Validations
Constructor Details
#initialize(type: nil) ⇒ Address
Returns a new instance of Address.
63 64 65 66 67 |
# File 'lib/adf_builder/nodes/shared.rb', line 63 def initialize(type: nil) super() @tag_name = :address @attributes[:type] = type if type end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AdfBuilder::Nodes::Node
Instance Method Details
#street(value, line: nil) ⇒ Object
78 79 80 81 |
# File 'lib/adf_builder/nodes/shared.rb', line 78 def street(value, line: nil) node = GenericNode.new(:street, { line: line }.compact, value) add_child(node) end |
#validate! ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/adf_builder/nodes/shared.rb', line 69 def validate! super streets = @children.select { |c| c.tag_name == :street } raise AdfBuilder::Error, "Address must have at least one street line" if streets.empty? return unless streets.size > 5 raise AdfBuilder::Error, "Address can have at most 5 street lines" end |