Class: XamplGenerator::YUMLOut

Inherits:
Object
  • Object
show all
Defined in:
lib/xamplr-gen/yuml-out.rb

Instance Method Summary collapse

Constructor Details

#initialize(elements_map) ⇒ YUMLOut

Returns a new instance of YUMLOut.



6
7
8
# File 'lib/xamplr-gen/yuml-out.rb', line 6

def initialize(elements_map)
  @elements_map = elements_map
end

Instance Method Details

#generate_class_nodes(element, include_mixins) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/xamplr-gen/yuml-out.rb', line 10

def generate_class_nodes(element, include_mixins)
  return if ignore_package(element.package)

  class_name = "#{ element.package }::#{ element.class_name }"
  mixin_name = "#{ element.package }::#{ element.class_name }"

  @class_by_nstag[element.nstag] = element
  @class_names_by_nstag[element.nstag] = class_name

  if element.persisted then
    write_entity_node(class_name, element.kind)
  else
    write_internal_node(class_name, element.kind)
  end

  if include_mixins then
    write_mixin_node(class_name)
  end
end

#generate_edges(element, include_mixins) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/xamplr-gen/yuml-out.rb', line 30

def generate_edges(element, include_mixins)
  return if ignore_package(element.package)

  element_name = @class_names_by_nstag[ element.nstag ]

  element.child_element_child.each do | celement |
    next if ignore_package(celement.package)

    celement_name = @class_names_by_nstag[ celement.name ]
    referenced_element = @class_by_nstag[ celement.name ]

    if referenced_element.persisted then
      write_entity_ref_edge(element_name, celement_name)
    else
      write_internal_ref_edge(element_name, celement_name)
    end
    if include_mixins then
      write_mixin_ref_edge(element_name, celement_name)
    end
  end
end

#ignore_package(package) ⇒ Object



52
53
54
55
56
57
# File 'lib/xamplr-gen/yuml-out.rb', line 52

def ignore_package(package)
  return true if @excluded_packages.member?(package)
  return false if @included_packages.nil?
  return true unless @included_packages.member?(package)
  return false
end

#new_statementObject



89
90
91
92
93
94
95
# File 'lib/xamplr-gen/yuml-out.rb', line 89

def new_statement
  if @initialise_output then
    @initialise_output = false
  else
    @out << ",\n"
  end
end

#write_entity_node(class_name, kind) ⇒ Object



97
98
99
100
# File 'lib/xamplr-gen/yuml-out.rb', line 97

def write_entity_node(class_name, kind)
  new_statement
  @out << "[#{ class_name }{bg:red}]"
end

#write_entity_ref_edge(class_node, external_node) ⇒ Object



112
113
114
115
# File 'lib/xamplr-gen/yuml-out.rb', line 112

def write_entity_ref_edge(class_node, external_node)
  new_statement
  @out << "[#{ class_node }]->[#{ external_node }]"
end

#write_internal_node(class_name, kind) ⇒ Object



102
103
104
105
# File 'lib/xamplr-gen/yuml-out.rb', line 102

def write_internal_node(class_name, kind)
  new_statement
  @out << "[#{ class_name }{bg:blue}]"
end

#write_internal_ref_edge(class_node, internal_node) ⇒ Object



117
118
119
120
# File 'lib/xamplr-gen/yuml-out.rb', line 117

def write_internal_ref_edge(class_node, internal_node)
  new_statement
  @out << "[#{ class_node }]->[#{ internal_node }]"
end

#write_mixin_node(class_name) ⇒ Object



107
108
109
110
# File 'lib/xamplr-gen/yuml-out.rb', line 107

def write_mixin_node(class_name)
  new_statement
  @out << "[#{ class_name }Mixin]"
end

#write_mixin_ref_edge(class_node, mixin_node) ⇒ Object



122
123
124
125
# File 'lib/xamplr-gen/yuml-out.rb', line 122

def write_mixin_ref_edge(class_node, mixin_node)
  new_statement
  @out << "[#{ mixin_node }Mixin]^[#{ class_node }]"
end

#write_yuml(base_filename, excluded_packages = [ ], included_packages = nil, include_mixins = false) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xamplr-gen/yuml-out.rb', line 59

def write_yuml(base_filename, excluded_packages=[ ], included_packages=nil, include_mixins=false)
  filename = "#{ base_filename }.yuml"

  @excluded_packages = Set.new(excluded_packages)
  @included_packages = included_packages ? Set.new(included_packages) : nil

  @class_names_by_nstag = {} # NOTE -- this is used by yuml!!
  @class_by_nstag = {} # NOTE -- this is used by yuml!!

  @initialise_output = true

  File.open(filename, "w") do | out |
    @out = out

    @elements_map.each_value do |elements|
      elements.element_child.each do |element|
        generate_class_nodes(element, include_mixins)
      end
    end

    @elements_map.each_value do |elements|
      elements.element_child.each do |element|
        generate_edges(element, include_mixins)
      end
    end
  end

  return nil
end