Class: RTM::Topology

Inherits:
Object
  • Object
show all
Defined in:
rtm/lib/rtm/topology.rb

Overview

Topology information about a Topic Map. This class provides some statistical and structural information about a topic map. All methods take an optional modifier OR block which specifies how a Topic Maps construct shall be transformed before it is returned. Some modifiers are defined in the sub module Modifier.

Defined Under Namespace

Modules: Modifier, TopologyExtension

Constant Summary

SINGLE_TYPED_CONSTRUCTS =

A list of constructs defined in TMDM which have a (single) type

%w[name occurrence association role]
TYPED_CONSTRUCTS =

A list of constructs defined in TMDM which may have multiple types

["topic"] + SINGLE_TYPED_CONSTRUCTS
SCOPEABLE_CONSTRUCTS =

A list of constructs defined in TMDM which are scopeable

%w[name variant occurrence association]

Instance Attribute Summary

Instance Method Summary

Constructor Details

- (Topology) initialize(topic_map)

A new instance of Topology



11
12
13
# File 'rtm/lib/rtm/topology.rb', line 11

def initialize(topic_map)
  @topic_map = topic_map
end

Instance Attribute Details

- (RTM::TopicMap) topic_map (readonly)

The topic map this topology provides information about.

Returns:

  • (RTM::TopicMap)

    The topic map this topology provides information about.



9
10
11
# File 'rtm/lib/rtm/topology.rb', line 9

def topic_map
  @topic_map
end

Instance Method Details

- (Hash) all(modifier = nil, &block)

All topology information in one step

Returns:

  • (Hash)

    with all topology information. Keys correspond to method names, values to their returned results.



77
78
79
80
81
82
# File 'rtm/lib/rtm/topology.rb', line 77

def all(modifier=nil, &block)
  modifier ||= block || Modifier.default
  puts "modifier: #{modifier.inspect}"
  ms = self.methods - Object.new.methods - %w[topic_map all]
  Hash[ms.map {|m| [m, self.send(m, modifier)]}]
end

- (Number) associations_count(modifier = nil, &block)

The number of associations in this topic map

Returns:

  • (Number)


60
61
62
# File 'rtm/lib/rtm/topology.rb', line 60

def associations_count(modifier=nil, &block)
  @topic_map.associations.size
end

- (String) to_s(modifier = nil, &block)

String representation of all topology information

Returns:

  • (String)

    with all topology information



86
87
88
89
# File 'rtm/lib/rtm/topology.rb', line 86

def to_s(modifier=nil, &block)
  modifier ||= block || Modifier.best_name
  all(modifier).sort_by{|k,v| k}.map {|k,v| "#{k}: #{v.inspect}"}.join("\n")
end

- (Number) topics_count(modifier = nil, &block)

The number of topics in this topic map

Returns:

  • (Number)


54
55
56
# File 'rtm/lib/rtm/topology.rb', line 54

def topics_count(modifier=nil, &block)
  @topic_map.topics.size
end