Class: Datacite::Mapping::GeoLocationNode
- Inherits:
-
XML::Mapping::SingleAttributeNode
- Object
- XML::Mapping::SingleAttributeNode
- Datacite::Mapping::GeoLocationNode
- Defined in:
- lib/datacite/mapping/geo_location_node.rb
Overview
Abstract superclass of GeoLocation parsing nodes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#coord_elements
readonly
Returns the value of attribute coord_elements.
-
#geom_class
readonly
Returns the value of attribute geom_class.
Instance Method Summary collapse
- #datacite_3? ⇒ Boolean
- #extract_attr_value(xml)
-
#initialize(*args) ⇒ GeoLocationNode
constructor
A new instance of GeoLocationNode.
- #set_attr_value(xml, value)
Constructor Details
#initialize(*args) ⇒ GeoLocationNode
Returns a new instance of GeoLocationNode.
12 13 14 15 16 17 18 19 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 12 def initialize(*args) raise 'No geometry class provided' unless @geom_class raise 'No coordinate elements provided' unless @coord_elements path, *myargs = super(*args) @path = ::XML::XXPath.new(path) myargs # rubocop:disable Lint/Void end |
Instance Attribute Details
#coord_elements (readonly)
Returns the value of attribute coord_elements.
10 11 12 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 10 def coord_elements @coord_elements end |
#geom_class (readonly)
Returns the value of attribute geom_class.
10 11 12 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 10 def geom_class @geom_class end |
Instance Method Details
#datacite_3? ⇒ Boolean
21 22 23 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 21 def datacite_3? mapping == :datacite_3 end |
#extract_attr_value(xml)
25 26 27 28 29 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 25 def extract_attr_value(xml) from_text(xml) || from_children(xml) rescue StandardError => e raise e, "#{@owner}.#{@attrname}: Can't extract #{self.class} from #{xml}: #{e.}" end |
#set_attr_value(xml, value)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/datacite/mapping/geo_location_node.rb', line 31 def set_attr_value(xml, value) raise "Invalid value: expected #{geom_class} instance, was #{value || 'nil'}" unless value.is_a?(geom_class) element = @path.first(xml, ensure_created: true) if datacite_3? element.text = value.to_s else coord_elements.each do |getter, element_name| child = element.elements << REXML::Element.new(element_name) child.text = value.send(getter) end end end |