Module: Lutaml::Uml::ModelHelpers
- Included in:
- Lutaml::UmlRepository::Exporters::Markdown::Formatting, Lutaml::UmlRepository::Exporters::MarkdownExporter, Lutaml::UmlRepository::StaticSite::DataTransformer, Lutaml::UmlRepository::StaticSite::Serializers::AttributeSerializer, Lutaml::UmlRepository::StaticSite::Serializers::ClassSerializer, Lutaml::UmlRepository::StaticSite::Serializers::InheritanceResolver, Lutaml::UmlRepository::StaticSite::Serializers::PackageSerializer, Lutaml::UmlRepository::StaticSite::Serializers::PackageTreeBuilder
- Defined in:
- lib/lutaml/uml/model_helpers.rb
Instance Method Summary collapse
- #class_type_for(uml_class) ⇒ Object
- #format_cardinality(cardinality) ⇒ Object
- #normalize_stereotypes(stereotype) ⇒ Object
- #package_path_for(uml_element) ⇒ Object
- #parse_cardinality(min, max) ⇒ Object
- #qualified_name_for(uml_element) ⇒ Object
Instance Method Details
#class_type_for(uml_class) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/lutaml/uml/model_helpers.rb', line 47 def class_type_for(uml_class) case uml_class when String then uml_class.split("::").last when Class then uml_class.name.split("::").last else uml_class.class.name.split("::").last end end |
#format_cardinality(cardinality) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lutaml/uml/model_helpers.rb', line 55 def format_cardinality(cardinality) return nil unless cardinality min = cardinality.min max = cardinality.max return nil if min.nil? && max.nil? min_str = min.nil? ? "0" : min.to_s max_str = max.nil? ? "*" : max.to_s "#{min_str}..#{max_str}" end |
#normalize_stereotypes(stereotype) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/lutaml/uml/model_helpers.rb', line 6 def normalize_stereotypes(stereotype) return [] if stereotype.nil? case stereotype when Array then stereotype.map(&:to_s) when String then [stereotype] when Symbol then [stereotype.to_s] else [stereotype.to_s] end end |
#package_path_for(uml_element) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lutaml/uml/model_helpers.rb', line 29 def package_path_for(uml_element) parts = [] current = uml_element while current if current.is_a?(Lutaml::Uml::Package) parts.unshift(current.name) if current.name current = current.namespace elsif current.is_a?(Lutaml::Uml::TopElement) current = current.namespace else break end end parts.join("::") end |
#parse_cardinality(min, max) ⇒ Object
67 68 69 |
# File 'lib/lutaml/uml/model_helpers.rb', line 67 def parse_cardinality(min, max) { min: min, max: max } end |
#qualified_name_for(uml_element) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lutaml/uml/model_helpers.rb', line 17 def qualified_name_for(uml_element) parts = [] current = uml_element while current parts.unshift(current.name) if current.name current = current.namespace end parts.join("::") end |