module NokoHacks
Public Instance Methods
build_ds(node, node_array, attr_accessor_hash)
click to toggle source
# File lib/noko_hacks.rb, line 54 def build_ds(node, node_array, attr_accessor_hash) case [node.attributes.empty? , node.content.empty? ,node.children.empty?] when [false, true, true] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')} }) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} when [true, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => node.content, :child_node => node.child_node_ds(attr_accessor_hash) }) && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content) when [false, true, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_')=> node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}, :child_node => node.child_node_ds(attr_accessor_hash) }) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} when [false, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => (node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}).merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content) }) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content) end end
child_node_ds(attr_accessor_hash)
click to toggle source
# File lib/noko_hacks.rb, line 68 def child_node_ds(attr_accessor_hash) _temp=[] self.children.each do |node| case [node.attributes.empty? , node.content.empty? ,node.children.empty?] when [false, true, true] then _temp.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}}) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} when [true, false, false] then _temp.push({(node.parent.name + encode_node_path(node)).gsub('-','_') => node.content, :child_node => node.child_node_ds(attr_accessor_hash) }) && attr_accessor_hash.merge!((node.parent.name + encode_node_path(node)).gsub('-','_') => node.content) when [false, true, false] then _temp.push({(node.name + encode_node_path(node)).gsub('-','_') => node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}, :child_node => node.child_node_ds(attr_accessor_hash)})&& node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} when [false, false, false] then node_array.push({(node.name + encode_node_path(node)).gsub('-','_') => (node.attributes.transform_keys{|key| (key + encode_node_path(node)).gsub('-','_')}).merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content)}) && node.attributes.each {|key,value| attr_accessor_hash.merge!((key + encode_node_path(node)).gsub('-','_') => value.value)} && attr_accessor_hash.merge!((node.name + encode_node_path(node)).gsub('-','_') => node.content) end end return _temp end
decode_node_path(node)
click to toggle source
# File lib/noko_hacks.rb, line 36 def decode_node_path(node) Base64.decode64(node.split('_').last) end
encode_node_path(node)
click to toggle source
# File lib/noko_hacks.rb, line 50 def encode_node_path(node) ('_' + Base64.urlsafe_encode64((Nokogiri::CSS.xpath_for node.css_path).first)).gsub('=','') end
get_node_attribute_name(key)
click to toggle source
# File lib/noko_hacks.rb, line 40 def get_node_attribute_name(key) (_split_key = key.split('_')).size > 2 ? _split_key.take(_split_key.size - 1).join('-').sub('@','') : _split_key.first.sub('@','') end
iterate_child_nodes(node_array, attr_accessor_hash)
click to toggle source
# File lib/noko_hacks.rb, line 44 def iterate_child_nodes(node_array, attr_accessor_hash) self.children.each do |node| build_ds(node, node_array, attr_accessor_hash) end end
remove_blank_node()
click to toggle source
# File lib/noko_hacks.rb, line 7 def remove_blank_node self.children.each do |node| if node.blank? node.remove end if node.children node.remove_blank_node end end end
update_xml(node, key, value)
click to toggle source
# File lib/noko_hacks.rb, line 26 def update_xml(node, key, value) case [node.content.empty?, node.attributes.empty?] when [false, true] then node.content = value when [false, false] then node.content = value && update_xml_attributes(node, key, value) when [true, false] then update_xml_attributes(node, key, value) end end
update_xml_attributes(node, key, value)
click to toggle source
# File lib/noko_hacks.rb, line 18 def update_xml_attributes(node, key, value) node.attributes.each do |k, v| if k == get_node_attribute_name(key) v.value = value end end end