yuml 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dfedd4143fa7f70413f2121222c644e571ab0ce
4
- data.tar.gz: 2aca47371b0fcb0fd79c36fca51eefa21168d987
3
+ metadata.gz: 907906ac9ee46b88eba7d9f9b1a257d7447bd1e4
4
+ data.tar.gz: 43fa6090d14dd0e37d339e5618f206a1c59e3876
5
5
  SHA512:
6
- metadata.gz: e4004dfaa42b37baa7461041eb00065863a78b30b70915a8772a8828648a96b0e433fbd85556431cb9d9b108b1210f88180359d2b6d78ea77ed8cab4380e959f
7
- data.tar.gz: 563158e7cefff93a7ff4e4ca4c13adf9e3751f6f7274ba4d336d9fd4bef7615b0102a5a4fdabaaa79b281ed6f3ae5b553cf1b64932b9350688f45ede3634c036
6
+ metadata.gz: 5888e4a2b4bc5c8e2cd76eaeedcf47f99f61b8dbea44841dc2426b7dd6df0295f8db06b6e7d63f0d4374c0ece61b9685abd2b3c5e1e9dd0fd9e18f847a2b63ad
7
+ data.tar.gz: 3a16c0f33d778d1033988bef97ee4bfb64df70ec07ec667fbcd1c1220143be52b97b3747361fc1ee9bd2fa736b85d606fc6a175a6d3bc527ab773f774bff699b
data/lib/yuml.rb CHANGED
@@ -3,16 +3,16 @@ require 'net/http'
3
3
  require 'yuml/class'
4
4
  require 'yuml/relationship'
5
5
 
6
+ # A module to create a DSL for yuml.me
6
7
  module YUML
7
8
  extend self
8
9
 
9
10
  ESCAPE_CHARACTERS = {
10
11
  '{' => "\u23A8",
11
- '}' => "\u23AC"
12
+ '}' => "\u23AC",
13
+ ',' => "\u201A"
12
14
  }
13
15
 
14
- ESCAPE_COMMA = "\u201A"
15
-
16
16
  def generate(options)
17
17
  options = { file: '/tmp/yuml.pdf' }.merge(options)
18
18
  classes.clear
@@ -47,6 +47,6 @@ module YUML
47
47
  end
48
48
 
49
49
  def encodings
50
- "#{ESCAPE_CHARACTERS.values.join}#{ESCAPE_COMMA}[](){}+->|,=;*^ "
50
+ "#{ESCAPE_CHARACTERS.values.join}[](){}+->|.,=;*^ "
51
51
  end
52
52
  end
data/lib/yuml/class.rb CHANGED
@@ -14,30 +14,27 @@ module YUML
14
14
  @name
15
15
  end
16
16
 
17
- def public_methods(*args)
18
- uml_methods('+', *args)
17
+ def variables(*args)
18
+ args.flatten!
19
+ return attributes(@variables) if args.empty?
20
+ @variables << normalize(args)
19
21
  end
20
22
 
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)
23
+ def methods(*args)
24
+ args.flatten!
25
+ return attributes(@methods) if args.empty?
26
+ @methods << normalize(args)
31
27
  end
32
28
 
33
29
  def has_a(dest, options = {})
34
- relationship = YUML::Relationship.relationship(options)
30
+ options[:type] = :aggregation unless %i(composition aggregation).include?(options[:type])
31
+ relationship = YUML::Relationship.send(options[:type], options[:cardinality])
35
32
  @relationships << "[#{name}]#{relationship}[#{dest.name}]"
36
33
  end
37
34
 
38
35
  def is_a(dest, options = {})
39
36
  options[:type] = :inheritance unless %i(inheritance interface).include?(options[:type])
40
- relationship = YUML::Relationship.relationship(options)
37
+ relationship = YUML::Relationship.send(options[:type])
41
38
  @relationships << "[#{dest.name}]#{relationship}[#{name}]"
42
39
  end
43
40
 
@@ -53,50 +50,11 @@ module YUML
53
50
 
54
51
  def normalize(values)
55
52
  values.map(&:to_s).map do |v|
56
- YUML::ESCAPE_CHARACTERS.each do |char, escape|
57
- v.tr!(char, escape)
58
- end
53
+ YUML::ESCAPE_CHARACTERS.each { |char, escape| v.tr!(char, escape) }
59
54
  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
55
  end
76
56
  end
77
57
 
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
58
  def attributes(attrs)
101
59
  "|#{attrs.join(';')}" unless attrs.empty?
102
60
  end
@@ -1,43 +1,29 @@
1
- # Represents a yUML relationship
2
1
  module YUML
2
+ # Represents UML class relationships
3
3
  module Relationship
4
- extend self
4
+ module_function
5
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)
6
+ def inheritance
7
+ '^-'
13
8
  end
14
9
 
15
- private
10
+ def interface
11
+ '^-.-'
12
+ end
16
13
 
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
14
+ def composition(*args)
15
+ "+#{aggregation(*args)}"
23
16
  end
24
17
 
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]}>"
18
+ def aggregation(*args)
19
+ args.flatten!
20
+ if args.size == 2
21
+ "+#{args[0]}-#{args[1]}>"
22
+ elsif args.size == 1
23
+ "+-#{args.first}>"
32
24
  else
33
- base << "-#{cardinality}>"
25
+ '+->'
34
26
  end
35
- base
36
- end
37
-
38
- def inheritance(type)
39
- return '^-.-' if type == :interface
40
- '^-'
41
27
  end
42
28
  end
43
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Stride
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-13 00:00:00.000000000 Z
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec