Class: ActiveFacts::Metamodel::Verbaliser::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/vocabulary/verbaliser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_type) ⇒ Player

Returns a new instance of Player.



103
104
105
106
107
108
109
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 103

def initialize object_type
  @object_type = object_type
  @variables_by_query = {}
  @subscript = nil
  @plays = []
  @role_refs = []
end

Instance Attribute Details

#object_typeObject

Returns the value of attribute object_type.



102
103
104
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 102

def object_type
  @object_type
end

#playsObject

Returns the value of attribute plays.



102
103
104
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 102

def plays
  @plays
end

#role_refsObject

Returns the value of attribute role_refs.



102
103
104
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 102

def role_refs
  @role_refs
end

#subscriptObject

Returns the value of attribute subscript.



102
103
104
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 102

def subscript
  @subscript
end

#variables_by_queryObject

Returns the value of attribute variables_by_query.



102
103
104
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 102

def variables_by_query
  @variables_by_query
end

Instance Method Details

#describeObject



129
130
131
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 129

def describe
  @object_type.name + (@variables_by_query.size > 0 ? " (in #{@variables_by_query.size} variables)" : "")
end

#role_adjuncts(matching) ⇒ Object

What words are used (across all roles) for disambiguating the references to this player? If more than one set of adjectives was used, this player must have been subject to loose binding. This method is used to decide when subscripts aren’t needed.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 114

def role_adjuncts matching
  if matching == :loose
    adjuncts = []
  else
    adjuncts = @role_refs.map{|rr|
      [
        rr.leading_adjective,
        matching == :rolenames ? rr.role.role_name : nil,
        rr.trailing_adjective
      ].compact}.uniq.sort
  end
  adjuncts += [@variables_by_query.values.map{|jn| jn.role_name}.compact[0]].compact
  adjuncts.flatten*"_"
end