Module: PLOS::XmlHelpers
- Included in:
- Affiliation, Article, ArticleRef, Contributor, Figure, Name, Reference
- Defined in:
- lib/plos/xml_helpers.rb
Instance Method Summary collapse
- #nodes_to_hash(nodes, attribute_name) ⇒ Object
- #parse_node(node, obj = nil) ⇒ Object
- #tag_value(node, tag_name) ⇒ Object
Instance Method Details
#nodes_to_hash(nodes, attribute_name) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/plos/xml_helpers.rb', line 27 def nodes_to_hash(nodes, attribute_name) hash = {} nodes.each do |node| key = node.attr(attribute_name) value = node.text hash[key] = value end hash end |
#parse_node(node, obj = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/plos/xml_helpers.rb', line 5 def parse_node(node, obj=nil) value = case(node.name) when "arr" node.xpath('./*').collect { |child| parse_node(child) } when "date" DateTime.parse(node.content) when "float" node.content.to_f else node.content end if node.attr("name") && obj && obj.respond_to?(:"#{node.attr("name")}=") obj.send(:"#{node.attr("name")}=", value) end value end |
#tag_value(node, tag_name) ⇒ Object
22 23 24 25 |
# File 'lib/plos/xml_helpers.rb', line 22 def tag_value(node,tag_name) child = node.search("#{tag_name}").first child.text if child end |