Class: Ea::Export::Xsd::ClassMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/export/xsd/class_mapping.rb

Overview

Loads EA's GMLClassMapping.xml and exposes per-class mapping rules: UML class name → GML element/type/propertyType names.

XML format:

<ClassMapping>
<Class name="FeatureType" element="featureMember"
      type="FeaturePropertyType" propertyType="..."
      typeContent="complex"/>
</ClassMapping>

Defined Under Namespace

Classes: Mapping

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappings = {}) ⇒ ClassMapping

Returns a new instance of ClassMapping.

Parameters:

  • mappings (Hash{String => Mapping}) (defaults to: {})

    keyed by UML class name



21
22
23
# File 'lib/ea/export/xsd/class_mapping.rb', line 21

def initialize(mappings = {})
  @mappings = mappings
end

Instance Attribute Details

#mappingsObject (readonly)

Returns the value of attribute mappings.



18
19
20
# File 'lib/ea/export/xsd/class_mapping.rb', line 18

def mappings
  @mappings
end

Class Method Details

.from_nokogiri(doc) ⇒ ClassMapping

Parameters:

  • doc (Nokogiri::XML::Document)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ea/export/xsd/class_mapping.rb', line 38

def self.from_nokogiri(doc)
  mappings = {}
  doc.xpath("//Class").each do |node|
    name = node["name"]
    next unless name

    mappings[name] = Mapping.new(
      name: name,
      element: node["element"],
      type: node["type"],
      property_type: node["propertyType"],
      type_content: node["typeContent"]
    )
  end
  new(mappings)
end

.from_path(path) ⇒ ClassMapping

Parameters:

  • path (String)

    path to GMLClassMapping.xml

Returns:



30
31
32
33
34
# File 'lib/ea/export/xsd/class_mapping.rb', line 30

def self.from_path(path)
  return new if path.nil? || !File.exist?(path)

  from_nokogiri(Nokogiri::XML(File.read(path)))
end

Instance Method Details

#for(class_name) ⇒ Mapping?

Look up a mapping by UML class name. Returns nil when no explicit mapping exists.

Parameters:

  • class_name (String)

Returns:



59
60
61
# File 'lib/ea/export/xsd/class_mapping.rb', line 59

def for(class_name)
  mappings[class_name]
end