Class: ActiveFacts::Metamodel::RoleRef

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb

Instance Method Summary collapse

Instance Method Details

#cql_leading_adjectiveObject



353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/activefacts/vocabulary/extensions.rb', line 353

def cql_leading_adjective
	if leading_adjective
	  # 'foo' => "foo-"
	  # 'foo bar' => "foo- bar "
	  # 'foo-bar' => "foo-- bar "
	  # 'foo-bar baz' => "foo-- bar baz "
	  # 'bat foo-bar baz' => "bat- foo-bar baz "
	  leading_adjective.strip.
	    sub(/[- ]|$/, '-\0 ').sub(/  /, ' ').sub(/[^-]$/, '\0 ').sub(/-  $/,'-')
	else
	  ''
	end
end

#cql_nameObject



385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/activefacts/vocabulary/extensions.rb', line 385

def cql_name
  if role.fact_type.all_role.size == 1
    role_name
  elsif role.role_name
    role.role_name
  else
    # Where an adjective has multiple words, the hyphen is inserted outside the outermost space, leaving the space
	  cql_leading_adjective +
      role.object_type.name+
	    cql_trailing_adjective
  end
end

#cql_trailing_adjectiveObject



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/activefacts/vocabulary/extensions.rb', line 367

def cql_trailing_adjective
	if trailing_adjective
	  # 'foo' => "-foo"
	  # 'foo bar' => " foo -bar"
	  # 'foo-bar' => " foo --bar"
	  # 'foo-bar baz' => " foo-bar -baz"
	  # 'bat foo-bar baz' => " bat foo-bar -baz"
	  trailing_adjective.
	    strip.
	    sub(/(?<a>.*) (?<b>[^- ]+$)|(?<a>.*)(?<b>-[^- ]*)$|(?<a>)(?<b>.*)/) {
 " #{$~[:a]} -#{$~[:b]}"
	    }.
	    sub(/^ *-/, '-')  # A leading space is not needed if the hyphen is at the start
	else
	  ''
	end
end

#describeObject



330
331
332
# File 'lib/activefacts/vocabulary/extensions.rb', line 330

def describe
  role_name
end

#preferred_referenceObject



334
335
336
# File 'lib/activefacts/vocabulary/extensions.rb', line 334

def preferred_reference
  role.preferred_reference
end

#role_name(separator = "-") ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/activefacts/vocabulary/extensions.rb', line 338

def role_name(separator = "-")
  return 'UNKNOWN' unless role
  name_array =
    if role.fact_type.all_role.size == 1
      if role.fact_type.is_a?(LinkFactType)
        "#{role.object_type.name} phantom for #{role.fact_type.role.object_type.name}"
      else
        role.fact_type.preferred_reading.text.gsub(/\{[0-9]\}/,'').strip.split(/\s/)
      end
    else
      role.role_name || [leading_adjective, role.object_type.name, trailing_adjective].compact.map{|w| w.split(/\s/)}.flatten
    end
  return separator ? Array(name_array)*separator : Array(name_array)
end