Class: AdfBuilder::Nodes::Contact
- Inherits:
-
Node
- Object
- Node
- AdfBuilder::Nodes::Contact
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
included
Constructor Details
#initialize(primary_contact: nil) ⇒ Contact
Returns a new instance of Contact.
99
100
101
102
103
|
# File 'lib/adf_builder/nodes/shared.rb', line 99
def initialize(primary_contact: nil)
super()
@tag_name = :contact
@attributes[:primarycontact] = primary_contact if primary_contact
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AdfBuilder::Nodes::Node
Instance Method Details
#address(type: nil, &block) ⇒ Object
125
126
127
128
129
|
# File 'lib/adf_builder/nodes/shared.rb', line 125
def address(type: nil, &block)
addr = Address.new(type: type)
addr.instance_eval(&block) if block_given?
add_child(addr)
end
|
#email(value, preferredcontact: nil) ⇒ Object
117
118
119
|
# File 'lib/adf_builder/nodes/shared.rb', line 117
def email(value, preferredcontact: nil)
add_child(Email.new(value, preferredcontact: preferredcontact))
end
|
#name(value, part: nil, type: nil) ⇒ Object
113
114
115
|
# File 'lib/adf_builder/nodes/shared.rb', line 113
def name(value, part: nil, type: nil)
add_child(Name.new(value, part: part, type: type))
end
|
#phone(value, type: nil, time: nil, preferredcontact: nil) ⇒ Object
121
122
123
|
# File 'lib/adf_builder/nodes/shared.rb', line 121
def phone(value, type: nil, time: nil, preferredcontact: nil)
add_child(Phone.new(value, type: type, time: time, preferredcontact: preferredcontact))
end
|
#validate! ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/adf_builder/nodes/shared.rb', line 105
def validate!
super
return if @children.any? { |c| i[phone email].include?(c.tag_name) }
raise AdfBuilder::Error, "Contact must have at least one Phone or Email"
end
|