Class: Lutaml::Model::Schema::XmlCompiler::Attribute

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

Constant Summary collapse

TEMPLATE =
ERB.new("<%= indent %>attribute :<%= resolved_name %>, :<%= resolved_type %>\n", trim_mode: "-")
XML_MAPPING_TEMPLATE =
ERB.new("<%= indent %>map_attribute :<%= resolved_name(change_case: false) %>, to: :<%= resolved_name %><%= namespace_prefix_option %>\n", trim_mode: "-")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, ref: nil) ⇒ Attribute

Returns a new instance of Attribute.



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

def initialize(name: nil, ref: nil)
  @name = name
  @ref = ref
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#refObject

Returns the value of attribute ref.



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

def ref
  @ref
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#required_filesObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/lutaml/model/schema/xml_compiler/attribute.rb', line 39

def required_files
  return if skippable?

  raw_type = resolved_type(change_case: false)
  if raw_type == "decimal"
    "require \"bigdecimal\""
  elsif !SimpleType.skippable?(raw_type)
    "require_relative \"#{Utils.snake_case(raw_type)}\""
  end
end

#to_attributes(indent) ⇒ Object



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

def to_attributes(indent)
  return if skippable?

  TEMPLATE.result(binding)
end

#to_xml_mapping(indent) ⇒ Object



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

def to_xml_mapping(indent)
  return if skippable?

  XML_MAPPING_TEMPLATE.result(binding)
end