Module: MyData::Xsd::Structure

Extended by:
Structure
Included in:
Structure
Defined in:
lib/my_data/xsd/structure.rb

Constant Summary collapse

PATH =
File.join(MyData.root, "lib/my_data/xsd/docs")

Instance Method Summary collapse

Instance Method Details

#complex_typesObject



28
29
30
31
32
33
34
35
# File 'lib/my_data/xsd/structure.rb', line 28

def complex_types
  @complex_types ||= docs.values.each_with_object({}) do |document, types|
    document.complex_types.each do |type|
      name = [type.namespace, type.name].compact.join(":")
      types[name] = type
    end
  end
end

#doc(class_name) ⇒ Object



8
9
10
11
# File 'lib/my_data/xsd/structure.rb', line 8

def doc(class_name)
  name = class_name.split("::").last
  [name, docs[name]]
end

#docsObject



22
23
24
25
26
# File 'lib/my_data/xsd/structure.rb', line 22

def docs
  @docs ||= Dir.glob("*.xsd", base: PATH).to_h do |file_name|
    [file_name.sub(/-.+$/, "").camelize, MyData::Xsd::Doc.new(read_xsd(file_name))]
  end
end

#resource_attributes(class_name, type) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/my_data/xsd/structure.rb', line 13

def resource_attributes(class_name, type)
  namespace, name = class_name.split("::").last(2)
  key = namespace == "Resources" ? name : [namespace.downcase, name].join(":")

  current_doc = type == :complex_type ? complex_types[key] : docs[name]

  current_doc.elements.map { |element| element_attributes(element) }
end

#simple_typesObject



37
38
39
40
41
42
43
44
# File 'lib/my_data/xsd/structure.rb', line 37

def simple_types
  @simple_types ||= docs.values.each_with_object({}) do |document, types|
    document.simple_types.each do |type|
      name = [type.namespace, type.name].compact.join(":")
      types[name] = type
    end
  end
end