Module: RTM::Sugar::Topic::Typed

Defined in:
rtm/lib/rtm/sugar/topic/typed.rb,
rtm/spec/rtm/sugar/topic/typed_spec.rb

Instance Method Summary

Instance Method Details

- (Boolean) topic_is_a?(type)

Determines whether this topic is instance (directly or indirectly) of the argument type.

Type may be a topic reference.

:call-seq:

  topic_is_a?(type)

Returns:

  • (Boolean)


154
155
156
157
158
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 154

def topic_is_a?(type)
  topic_map.cached self, :is_a?, type do
    self.transitive_types.include?(topic_map.get(type))
  end
end

- (Object) transitive_typed

Returns the associations, names, occurrences and roles whose type equals this topic or subtypes of this topic.

The result may be empty.

:call-seq:

  transitive_typed -> Array of Associations, Names, Occurrences and Roles


30
31
32
33
34
35
36
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 30

def transitive_typed
  trans_typed = typed #may be empty
  transitive_subtypes.each do |subtype|
    trans_typed.concat(subtype.typed)
  end
  trans_typed = trans_typed.uniq #no duplicates outside of tmql mode
end

- (Object) transitive_typed_associations

Returns the associations whose type equals this topic or subtypes of this topic.

The result may be empty.

:call-seq:

  transitive_typed_associations -> Array of Associations


57
58
59
60
61
62
63
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 57

def transitive_typed_associations
  trans_types_assocs = typed_associations #may be empty
  transitive_subtypes.each do |subtype|
    trans_types_assocs.concat(subtype.typed_associations)
  end
  trans_types_assocs = trans_types_assocs.uniq #no duplicates outside of tmql mode
end

- (Object) transitive_typed_names

Returns the names whose type equals this topic or subtypes of this topic.

The result may be empty.

:call-seq:

  transitive_typed_names -> Array of Associations


84
85
86
87
88
89
90
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 84

def transitive_typed_names
  trans_types_names = typed_names #may be empty
  transitive_subtypes.each do |subtype|
    trans_types_names.concat(subtype.typed_names)
  end
  trans_types_names = trans_types_names.uniq #no duplicates outside of tmql mode
end

- (Object) transitive_typed_occurrences

Returns the occurrences whose type equals this topic or subtypes of this topic.

The result may be empty.

:call-seq:

  transitive_typed_occurrences -> Array of Associations


111
112
113
114
115
116
117
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 111

def transitive_typed_occurrences
  trans_types_occs = typed_occurrences #may be empty
  transitive_subtypes.each do |subtype|
    trans_types_occs.concat(subtype.typed_occurrences)
  end
  trans_types_occs = trans_types_occs.uniq #no duplicates outside of tmql mode
end

- (Object) transitive_typed_roles

Returns the roles whose type equals this topic or subtypes of this topic.

The result may be empty.

:call-seq:

  transitive_typed_roles -> Array of Associations


138
139
140
141
142
143
144
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 138

def transitive_typed_roles
  trans_types_roles = typed_roles #may be empty
  transitive_subtypes.each do |subtype|
    trans_types_roles.concat(subtype.typed_roles)
  end
  trans_types_roles = trans_types_roles.uniq #no duplicates outside of tmql mode
end

- (Object) typed

Returns the associations, names, occurrences and roles whose type equals this topic.

The result may be empty.

:call-seq:

  typed -> Array of Associations, Names, Occurrences and Roles


16
17
18
19
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 16

def typed
  _index = topic_map.type_instance_index
  _index.get_associations(self).to_a + _index.get_names(self).to_a + _index.get_occurrences(self).to_a + _index.get_roles(self).to_a
end

- (Object) typed_associations

Returns the associations whose type equals this topic.

The result may be empty.

:call-seq:

  typed_associations -> Array of Associations


45
46
47
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 45

def typed_associations
  topic_map.type_instance_index.get_associations(self).to_a
end

- (Object) typed_names

Returns the names whose type equals this topic.

The result may be empty.

:call-seq:

  typed_names -> Array of Names


72
73
74
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 72

def typed_names
  topic_map.type_instance_index.get_names(self).to_a
end

- (Object) typed_occurrences

Returns the occurrences whose type equals this topic.

The result may be empty.

:call-seq:

  typed_occurrences -> Array of Occurrences


99
100
101
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 99

def typed_occurrences
  topic_map.type_instance_index.get_occurrences(self).to_a
end

- (Object) typed_roles

Returns the roles whose type equals this topic.

The result may be empty.

:call-seq:

  typed_roles -> Array of Roles


126
127
128
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 126

def typed_roles
  topic_map.type_instance_index.get_roles(self).to_a
end

- (Boolean) used_as_association_type?

States if this topic is used as type of an Association.

:call-seq:

  used_as_association_type? -> true or false

Returns:

  • (Boolean)


174
175
176
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 174

def used_as_association_type?
  not self.typed_associations.empty?
end

- (Boolean) used_as_name_type?

States if this topic is used as type of a Name.

:call-seq:

  used_as_name_type? -> true or false

Returns:

  • (Boolean)


183
184
185
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 183

def used_as_name_type?
  not self.typed_names.empty?
end

- (Boolean) used_as_occurrence_type?

States if this topic is used as type of an Occurrence.

:call-seq:

  used_as_occurrence_type -> true or false

Returns:

  • (Boolean)


192
193
194
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 192

def used_as_occurrence_type?
  not self.typed_occurrences.empty?
end

- (Boolean) used_as_role_type?

States if this topic is used as type of a Role.

:call-seq:

  used_as_role_type? -> true or false

Returns:

  • (Boolean)


201
202
203
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 201

def used_as_role_type?
  not self.typed_roles.empty?
end

- (Boolean) used_as_type?

States if this topic is used as type of a typed Construct.

:call-seq:

  used_as_type? -> true or false

Returns:

  • (Boolean)


165
166
167
# File 'rtm/lib/rtm/sugar/topic/typed.rb', line 165

def used_as_type?
  used_as_name_type? || used_as_occurrence_type? || used_as_association_type? || used_as_role_type?
end