Class: AdfBuilder::Nodes::Address

Inherits:
Node
  • Object
show all
Defined in:
lib/adf_builder/nodes/shared.rb

Instance Attribute Summary

Attributes inherited from Node

#attributes, #children, #tag_name, #value

Instance Method Summary collapse

Methods inherited from Node

#add_child, #method_missing, #remove_children, #respond_to_missing?, #to_xml

Methods included from Validations

included

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

Raises:



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