class Datacite::Mapping::BreakPreservingValueNode
XML
mapping class preserving `<br/>` tags in description values
Public Instance Methods
obj_to_xml(obj, xml)
click to toggle source
Converts a string value to a sequence of text nodes and `<br/>` tags. Implements `SingleAttributeNode#obj_to_xml`. @param obj [Description] the object being serialized @param xml [REXML::Element] the XML
being written
# File lib/datacite/mapping/description.rb, line 45 def obj_to_xml(obj, xml) value_str = obj.value || '' values = value_str.split(%r{<br[^/]?/>|<br>[^<]*</br>}) values.each_with_index do |v, i| xml.add_text(v) xml.add_element('br') unless i + 1 >= values.size end end
xml_to_obj(obj, xml)
click to toggle source
Collapses a sequence of text nodes and `<br/>` tags into a single string value. Implements `SingleAttributeNode#xml_to_obj`. @param obj [Description] the object being created @param xml [REXML::Element] the XML
being read
# File lib/datacite/mapping/description.rb, line 36 def xml_to_obj(obj, xml) value_str = xml.children.map { |c| c.respond_to?(:value) ? c.value : c.to_s }.join obj.value = value_str.strip end