Module: Goldendocx::HasAttributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Element
- Defined in:
- lib/goldendocx/has_attributes.rb
Instance Method Summary collapse
Instance Method Details
#assign_attributes(**attributes) ⇒ Object
63 64 65 |
# File 'lib/goldendocx/has_attributes.rb', line 63 def assign_attributes(**attributes) attributes.each { |key, value| send("#{key}=", value) if respond_to?("#{key}=") } end |
#attributes ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/goldendocx/has_attributes.rb', line 41 def attributes self.class.attributes.each_with_object({}) do |(name, ), result| value = public_send([:method] || name) || [:default] next if value.nil? key = [[:namespace], [:alias_name] || name].compact.join(':') result[key] = value end end |
#read_attributes(node) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/goldendocx/has_attributes.rb', line 51 def read_attributes(node) node_attributes = node.attributes_hash attributes = self.class.attributes.each_with_object({}) do |(name, ), result| attribute_tag = [[:namespace], ([:alias_name] || name)].compact.join(':') result[name] = node_attributes.delete(attribute_tag) end assign_attributes(**attributes) unparsed_attributes.update(node_attributes) end |