Class: Lutaml::Model::Schema::XmlCompiler::Restriction

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

Constant Summary collapse

MIN_MAX_BOUNDS =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  <%= "\#{indent}options[:max] = \#{max_inclusive || max_exclusive}" if max_bound_exist? %>
  <%= "\#{indent}options[:min] = \#{min_inclusive || min_exclusive}" if min_bound_exist? %>
TEMPLATE
PATTERN =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  <%= "\#{indent}options[:pattern] = %r{\#{pattern}}" %>
TEMPLATE
ENUMERATIONS =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  <%= "\#{indent}options[:values] = [\#{casted_enumerations}]" %>
TEMPLATE
TRANSFORM =
ERB.new(<<~TEMPLATE, trim_mode: "-")
  <%= "\#{indent}value = \#{transform}" %>
TEMPLATE

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_classObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def base_class
  @base_class
end

#enumerationsObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def enumerations
  @enumerations
end

#lengthObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def length
  @length
end

#max_exclusiveObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def max_exclusive
  @max_exclusive
end

#max_inclusiveObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def max_inclusive
  @max_inclusive
end

#max_lengthObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def max_length
  @max_length
end

#min_exclusiveObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def min_exclusive
  @min_exclusive
end

#min_inclusiveObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def min_inclusive
  @min_inclusive
end

#min_lengthObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def min_length
  @min_length
end

#patternObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def pattern
  @pattern
end

#transformObject

transform is not a ‘xsd’ type, but it is used for internal purposes.



9
10
11
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 9

def transform
  @transform
end

Instance Method Details

#required_filesObject



47
48
49
50
51
52
53
54
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 47

def required_files
  if base_class_name == :decimal
    "require \"bigdecimal\""
  elsif !SimpleType::SUPPORTED_DATA_TYPES.dig(base_class_name,
                                              :skippable)
    "require_relative \"#{Utils.snake_case(base_class_name)}\""
  end
end

#to_method_body(indent = nil) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/lutaml/model/schema/xml_compiler/restriction.rb', line 38

def to_method_body(indent = nil)
  [
    value_for(ENUMERATIONS, type: :enumerations, indent: indent),
    value_for(MIN_MAX_BOUNDS, type: :min_max_bounds, indent: indent),
    value_for(PATTERN, type: :pattern, indent: indent),
    value_for(TRANSFORM, type: :transform, indent: indent),
  ].compact.join
end