Module: Juniter::HasAttributes
- Included in:
- Element
- Defined in:
- lib/juniter/has_attributes.rb
Defined Under Namespace
Modules: ClassMethods
Classes: UnsetAttributeError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
6
7
8
|
# File 'lib/juniter/has_attributes.rb', line 6
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#assign_attributes_from_xml(node) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/juniter/has_attributes.rb', line 45
def assign_attributes_from_xml(node)
attributes = node.attributes
self.class.attributes.each do |name|
key = self.class.attribute_aliases.fetch(name, name).to_sym
mapped = attributes.key?(key) ? self.class.attribute_processors[name].call(node[key]) : nil
public_send "#{name}=", mapped
end
end
|
#xml_attributes ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/juniter/has_attributes.rb', line 54
def xml_attributes
self.class.attributes.each_with_object({}) do |name, hash|
key = self.class.attribute_aliases.fetch(name, name)
value = public_send(name)
raise UnsetAttributeError if self.class.required_attributes.include?(name) && value.nil?
hash[key] = public_send(name)
end
end
|