Class: Datacite::Mapping::GeoLocationNode

Inherits:
XML::Mapping::SingleAttributeNode
  • Object
show all
Defined in:
lib/datacite/mapping/geo_location_node.rb

Overview

Abstract superclass of GeoLocation parsing nodes

Direct Known Subclasses

GeoLocationBoxNode, GeoLocationPointNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GeoLocationNode

Returns a new instance of GeoLocationNode.



11
12
13
14
15
16
17
# File 'lib/datacite/mapping/geo_location_node.rb', line 11

def initialize(*args)
  fail 'No geometry class provided' unless @geom_class
  fail 'No coordinate elements provided' unless @coord_elements
  path, *args = super(*args)
  @path = ::XML::XXPath.new(path)
  args
end

Instance Attribute Details

#coord_elements (readonly)

Returns the value of attribute coord_elements.



9
10
11
# File 'lib/datacite/mapping/geo_location_node.rb', line 9

def coord_elements
  @coord_elements
end

#geom_class (readonly)

Returns the value of attribute geom_class.



8
9
10
# File 'lib/datacite/mapping/geo_location_node.rb', line 8

def geom_class
  @geom_class
end

Instance Method Details

#datacite_3?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/datacite/mapping/geo_location_node.rb', line 19

def datacite_3?
  mapping == :datacite_3
end

#extract_attr_value(xml)



23
24
25
26
27
# File 'lib/datacite/mapping/geo_location_node.rb', line 23

def extract_attr_value(xml)
  return from_text(xml) || from_children(xml)
rescue => e
  raise e, "#{@owner}.#{@attrname}: Can't extract #{self.class} from #{xml}: #{e.message}"
end

#set_attr_value(xml, value)

rubocop:disable Metrics/AbcSize



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/datacite/mapping/geo_location_node.rb', line 29

def set_attr_value(xml, value) # rubocop:disable Metrics/AbcSize
  fail "Invalid value: expected #{geom_class} instance, was #{value || 'nil'}" unless value && 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