Module: Cuporter::Node::InitializeNode
- Defined in:
- lib/cuporter/node/node_base.rb
Overview
common methods for building either html or xml nodes
Instance Method Summary collapse
- #copy_attrs(node, attributes) ⇒ Object
- #format_name(name) ⇒ Object
- #new_node(name, doc, attributes = {}) ⇒ Object
Instance Method Details
#copy_attrs(node, attributes) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/cuporter/node/node_base.rb', line 92 def copy_attrs(node, attributes) attributes.each do |attr, value| next if attr.to_s.downcase == 'type' value = value.is_a?(Array) ? value.join(", ") : value.to_s.strip node[attr.to_s] = value unless value.empty? end node end |
#format_name(name) ⇒ Object
86 87 88 89 90 |
# File 'lib/cuporter/node/node_base.rb', line 86 def format_name(name) node_name = name.to_s.gsub(/([a-z])([A-Z])/,'\1_\2').downcase class_name = name.to_s.to_class_name.to_sym return node_name, class_name end |
#new_node(name, doc, attributes = {}) ⇒ Object
101 102 103 104 105 |
# File 'lib/cuporter/node/node_base.rb', line 101 def new_node(name, doc, attributes = {}) node_name, class_name = format_name(name) n = Cuporter::Node::Types.const_get(class_name).new(node_name, doc) copy_attrs(n, attributes) end |