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_nameObject



222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/activefacts/vocabulary/extensions.rb', line 222

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
    (leading_adjective ? leading_adjective.strip.sub(/ |$/, '-\0').sub(/[^-]$/,'\0 ') : '') +
      role.object_type.name+
      (trailing_adjective ? ' '+trailing_adjective.strip.sub(/.* |^/, '\0-').sub(/^[^-]/,' \0') : '')
  end
end

#describeObject



199
200
201
# File 'lib/activefacts/vocabulary/extensions.rb', line 199

def describe
  role_name
end

#preferred_referenceObject



203
204
205
# File 'lib/activefacts/vocabulary/extensions.rb', line 203

def preferred_reference
  role.preferred_reference
end

#role_name(separator = "-") ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/activefacts/vocabulary/extensions.rb', line 207

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