Module: Suma::SchemaNaming

Defined in:
lib/suma/schema_naming.rb

Overview

Converts EXPRESS schema identifiers into human-readable display names.

Naming is model-driven: the schema type (resource/module) and suffix determine how the identifier is formatted. Acronyms and numeric prefixes are preserved to match ISO 10303 conventions.

Examples:

SchemaNaming.display_name("topology_schema")
# => "Topology"
SchemaNaming.display_name("Activity_method_assignment_mim")
# => "Activity Method Assignment (MIM)"
SchemaNaming.display_name("aic_advanced_brep")
# => "AIC Advanced Brep"

Constant Summary collapse

ACRONYMS =

Acronyms preserved as uppercase during title-casing. Source: ISO 10303 naming conventions.

%w[
  aic aec apu bom csg edraw id ifc pdf pld
  xml xpdl 2d 3d
].freeze
LOWERCASE_WORDS =

Lowercase function words (ISO title-case convention).

%w[a an and as for in of on or the to].freeze
SUFFIXES =

Suffixes stripped from the schema name before title-casing, mapped to the parenthesised label appended to the display name. A nil label means the suffix is stripped silently.

{
  "_arm" => "ARM",
  "_mim" => "MIM",
  "_bom" => "BOM",
  "_schema" => nil,
}.freeze

Class Method Summary collapse

Class Method Details

.category_prefix(type) ⇒ String

Determine the category prefix for a schema type.

Parameters:

  • type (Symbol)

    one of ExpressSchema::Type constants

Returns:

  • (String)


64
65
66
# File 'lib/suma/schema_naming.rb', line 64

def category_prefix(type)
  SchemaCategory.for_type(type).prefix
end

.display_name(schema_id) ⇒ String

Produce a human-readable display name from a schema identifier.

Parameters:

  • schema_id (String)

    the EXPRESS schema identifier

Returns:

  • (String)

    human-readable name



43
44
45
46
47
# File 'lib/suma/schema_naming.rb', line 43

def display_name(schema_id)
  base, label = decompose(schema_id)
  title_cased = title_case(base)
  label ? "#{title_cased} (#{label})" : title_cased
end

.prefixed_name(schema_id, path: nil) ⇒ String

Produce a prefixed display name with the schema category.

Parameters:

  • schema_id (String)

    the EXPRESS schema identifier

  • path (String, Pathname) (defaults to: nil)

    the schema file path (for classification)

Returns:

  • (String)

    e.g. "Resource: Topology" or "Module: Activity (ARM)"



54
55
56
57
58
# File 'lib/suma/schema_naming.rb', line 54

def prefixed_name(schema_id, path: nil)
  type = ExpressSchema::Type.classify(id: schema_id, path: path)
  prefix = category_prefix(type)
  "#{prefix}: #{display_name(schema_id)}"
end