Class: Lutaml::Model::Schema::XmlCompiler::Choice

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/xml_compiler/choice.rb

Constant Summary collapse

INDENT =
"  "
TEMPLATE =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  <%= indent %>choice<%= block_options %> do
  <%= instances.map { |instance| instance.to_attributes(indent + INDENT) }.join -%>
  <%= indent %>end
TEMPLATE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChoice

Returns a new instance of Choice.



18
19
20
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 18

def initialize
  @instances = []
end

Instance Attribute Details

#instancesObject

Returns the value of attribute instances.



8
9
10
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 8

def instances
  @instances
end

#max_occursObject

Returns the value of attribute max_occurs.



8
9
10
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 8

def max_occurs
  @max_occurs
end

#min_occursObject

Returns the value of attribute min_occurs.



8
9
10
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 8

def min_occurs
  @min_occurs
end

Instance Method Details

#<<(instance) ⇒ Object



22
23
24
25
26
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 22

def <<(instance)
  return if instance.nil?

  @instances << instance
end

#required_filesObject



38
39
40
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 38

def required_files
  @instances.flat_map(&:required_files).compact
end

#to_attributes(indent = INDENT) ⇒ Object



28
29
30
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 28

def to_attributes(indent = INDENT)
  TEMPLATE.result(binding)
end

#to_xml_mapping(indent = INDENT) ⇒ Object



32
33
34
35
36
# File 'lib/lutaml/model/schema/xml_compiler/choice.rb', line 32

def to_xml_mapping(indent = INDENT)
  instances.filter_map do |instance|
    instance.to_xml_mapping(indent)
  end.join
end