Class: ActiveFacts::Metamodel::Instance

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

Instance Method Summary collapse

Instance Method Details

#verbalise(context = nil) ⇒ Object



797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/activefacts/vocabulary/extensions.rb', line 797

def verbalise(context = nil)
  return "#{concept.name} #{value}" if concept.is_a?(ValueType)

  return "#{concept.name} where #{fact.verbalise(context)}" if concept.fact_type

  # It's an entity that's not an objectified fact type
  # REVISIT: If it has a simple identifier, there's no need to fully verbalise the identifying facts
  pi = concept.preferred_identifier
  identifying_role_refs = pi.role_sequence.all_role_ref_in_order
  "#{concept.name}" +
    " is identified by " +      # REVISIT: Where the single fact type is TypeInheritance, we can shrink this
    if identifying_role_refs.size == 1 &&
      (role = identifying_role_refs[0].role) &&
      (my_role = (role.fact_type.all_role.to_a-[role])[0]) &&
      (identifying_fact = my_role.all_role_value.detect{|rv| rv.instance == self}.fact) &&
      (identifying_instance = identifying_fact.all_role_value.detect{|rv| rv.role == role}.instance)

        "its #{identifying_instance.verbalise(context)}"
    else
      identifying_role_refs.map do |rr|
        rr = rr.preferred_role_ref
        [ (l = rr.leading_adjective) ? l+"-" : nil,
          rr.role.role_name || rr.role.concept.name,
          (t = rr.trailing_adjective) ? l+"-" : nil
        ].compact*""
      end * " and " +
      " where " +
      identifying_role_refs.map do |rr|  # Go through the identifying roles and emit the facts that define them
        instance_role = concept.all_role.detect{|r| r.fact_type == rr.role.fact_type}
        identifying_fact = all_role_value.detect{|rv| rv.fact.fact_type == rr.role.fact_type}.fact
        #counterpart_role = (rr.role.fact_type.all_role.to_a-[instance_role])[0]
        #identifying_instance = counterpart_role.all_role_value.detect{|rv| rv.fact == identifying_fact}.instance
        identifying_fact.verbalise(context)
      end*", "
    end

end