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

#==(role_ref) ⇒ Object

Two RoleRefs are equal if they have the same role and Joins with matching roles



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/activefacts/vocabulary/extensions.rb', line 90

def ==(role_ref)
  RoleRef === role_ref &&
  role_ref.role == role &&
  all_join.size == role_ref.all_join.size &&
  !all_join.sort_by{|j|j.join_step}.
    zip(role_ref.all_join.sort_by{|j|j.join_step}).
    detect{|j1,j2|
      j1.input_role != j2.input_role ||
      j1.output_role != j2.output_role
    }
end

#describeObject



74
75
76
77
# File 'lib/activefacts/vocabulary/extensions.rb', line 74

def describe
  # The reference traverses the Joins in sequence to the final role:
  all_join.sort_by{|jp| jp.join_step}.map{ |jp| jp.describe + "." }*"" + role_name
end

#role_name(joiner = "-") ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/activefacts/vocabulary/extensions.rb', line 79

def role_name(joiner = "-")
  name_array =
    if role.fact_type.all_role.size == 1
      role.fact_type.preferred_reading.reading_text.gsub(/\{[0-9]\}/,'').strip.split(/\s/)
    else
      role.role_name || [leading_adjective, role.concept.name, trailing_adjective].compact.map{|w| w.split(/\s/)}.flatten
    end
  return joiner ? Array(name_array)*joiner : Array(name_array)
end