yuml 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yuml/class.rb +104 -0
- data/lib/yuml/relationship.rb +43 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2be29a1f70df149897fb3a989fd9e2cd238c2a
|
4
|
+
data.tar.gz: 81759243732e3cbc3bdfd2aa91f8262b09fdd016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57d0e5129d522935c1dc6ef5300d4a825c2534f897db5102dc7ba1627768c4136fc8364dbd9e09d11f2a4fe0120c6126a3a521711d7654be6bae7ad7671c29f0
|
7
|
+
data.tar.gz: c8399b330ec6b1c4982559b3a1523ab0fe86ddbd66eb239890339e097950e8ba524df1e6f1a8b1b60e785d404531101e5f6c9f3226515d2284ab8157772a7046
|
data/lib/yuml/class.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
module YUML
|
2
|
+
# Represents a yUML Class
|
3
|
+
class Class
|
4
|
+
attr_writer :name
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@methods = []
|
8
|
+
@variables = []
|
9
|
+
@relationships = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def name(name = nil)
|
13
|
+
@name = name if name
|
14
|
+
@name
|
15
|
+
end
|
16
|
+
|
17
|
+
def public_methods(*args)
|
18
|
+
uml_methods('+', *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def private_methods(*args)
|
22
|
+
uml_methods('-', *args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def public_variables(*args)
|
26
|
+
uml_variables('+', *args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def private_variables(*args)
|
30
|
+
uml_variables('-', *args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_a(dest, options = {})
|
34
|
+
relationship = YUML::Relationship.relationship(options)
|
35
|
+
@relationships << "[#{name}]#{relationship}[#{dest.name}]"
|
36
|
+
end
|
37
|
+
|
38
|
+
def is_a(dest, options = {})
|
39
|
+
options[:type] = :inheritance unless %i(inheritance interface).include?(options[:type])
|
40
|
+
relationship = YUML::Relationship.relationship(options)
|
41
|
+
@relationships << "[#{dest.name}]#{relationship}[#{name}]"
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
"[#{name}#{variables}#{methods}]"
|
46
|
+
end
|
47
|
+
|
48
|
+
def relationships
|
49
|
+
"#{@relationships.join(',')}" unless @relationships.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def normalize(values)
|
55
|
+
values.map(&:to_s).map do |v|
|
56
|
+
YUML::ESCAPE_CHARACTERS.each do |char, escape|
|
57
|
+
v.tr!(char, escape)
|
58
|
+
end
|
59
|
+
v
|
60
|
+
end.join("\u201A ")
|
61
|
+
end
|
62
|
+
|
63
|
+
def uml_variables(scope, *args)
|
64
|
+
args.each { |var| variable(scope: scope, attribute: var) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def uml_methods(scope, *args)
|
68
|
+
args.each do |m|
|
69
|
+
if m.class == Hash
|
70
|
+
mets = m.map { |k, v| "#{k}(#{normalize(v)})" }
|
71
|
+
mets.each { |met| method(scope: scope, attribute: met) }
|
72
|
+
else
|
73
|
+
method(scope: scope, attribute: "#{m}()")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def method(options)
|
79
|
+
attribute(@methods, options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def variable(options)
|
83
|
+
attribute(@variables, options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def attribute(attributes, options)
|
87
|
+
scope = options[:scope] || '+'
|
88
|
+
scope = '+' unless %w(+ -).include?(scope)
|
89
|
+
attributes << "#{scope}#{options.fetch(:attribute)}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def methods
|
93
|
+
attributes(@methods)
|
94
|
+
end
|
95
|
+
|
96
|
+
def variables
|
97
|
+
attributes(@variables)
|
98
|
+
end
|
99
|
+
|
100
|
+
def attributes(attrs)
|
101
|
+
"|#{attrs.join(';')}" unless attrs.empty?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Represents a yUML relationship
|
2
|
+
module YUML
|
3
|
+
module Relationship
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def relationship(options)
|
7
|
+
options = { type: :aggregation }.merge(options)
|
8
|
+
types = %i(aggregation composition inheritance interface)
|
9
|
+
type = options[:type]
|
10
|
+
type = :aggregation unless types.include?(type)
|
11
|
+
cardinality = options[:cardinality]
|
12
|
+
representation(type, cardinality)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def representation(type, cardinality)
|
18
|
+
if %i(aggregation composition).include?(type)
|
19
|
+
return composition(type, cardinality)
|
20
|
+
elsif %i(inheritance interface).include?(type)
|
21
|
+
return inheritance(type)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def composition(type, cardinality)
|
26
|
+
base = '+'
|
27
|
+
base << '+' if type == :composition
|
28
|
+
if cardinality.nil?
|
29
|
+
base << '->'
|
30
|
+
elsif cardinality.class == Array && cardinality.length == 2
|
31
|
+
base << "#{cardinality[0]}-#{cardinality[1]}>"
|
32
|
+
else
|
33
|
+
base << "-#{cardinality}>"
|
34
|
+
end
|
35
|
+
base
|
36
|
+
end
|
37
|
+
|
38
|
+
def inheritance(type)
|
39
|
+
return '^-.-' if type == :interface
|
40
|
+
'^-'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Stride
|
@@ -31,6 +31,8 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/yuml.rb
|
34
|
+
- lib/yuml/class.rb
|
35
|
+
- lib/yuml/relationship.rb
|
34
36
|
homepage: https://github.com/DerekStride/yuml
|
35
37
|
licenses:
|
36
38
|
- MIT
|