yuml 0.4.0 → 0.4.1

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: 309834061e6f7f3f42c926fe7a57261a3d72cd7b
4
- data.tar.gz: 9c681e097d910258cf71ede0f49fb892e09dfdbf
3
+ metadata.gz: 08d748325a616407967febe42befb19be51ca4b6
4
+ data.tar.gz: 3366bcee2cb3dd6009a426a4e5114859ecaa5003
5
5
  SHA512:
6
- metadata.gz: f009740b9a5333ec255bd2e1401102ab557766935dbd8aeefea58ee344c03bc0bd15d86c12f2ac23b0ef1fb88d497196878eba363e691fb533f85994891dfbe1
7
- data.tar.gz: af3d8b66b1870167705f33adf42e0e8ee2fa094031e7108a227ea239e90365e8649d0b284b420eafe34fbd1963fa38ab637a31ff22cb01649203299a1b02cc77
6
+ metadata.gz: b7720f885df0dd8fe38d71223c7c8e221d30fc867435fde0e8554cba425413e5790dd8abd5d2c04f8d99c2930dbe1d996cfbba85926378ea0ee8fc75f3de7cd5
7
+ data.tar.gz: 11ff15392add8a1c50919e6badddd4bedc8996573958cd12e55c383b04d52430c0c592c25c29f16c717c488e35905b11f5345e648fd650c847e231604e8a7ddb
data/README.md CHANGED
@@ -16,9 +16,12 @@ end
16
16
 
17
17
  To generate a class for the document use `uml.class` and pass a code block in to configure it. It accepts the following methods for configuration.
18
18
 
19
- * name (required)
20
- * variables
21
- * methods
19
+ * `name(name = nil)` (required)
20
+ * `interface(interface = nil, sterotype = 'interface')`*
21
+ * `variables(*args)`
22
+ * `methods(*args)`
23
+
24
+ \*use `interface` in place of `name` when generating an interface
22
25
 
23
26
  #### Example
24
27
 
@@ -34,6 +37,13 @@ document = uml.class do
34
37
  end
35
38
  ```
36
39
 
40
+ ```ruby
41
+ shape = uml.class do
42
+ interface 'Shape', 'module'
43
+ methods '+draw(id: int, content: String, style: Symbol)'
44
+ end
45
+ ```
46
+
37
47
  ### Adding Relationships
38
48
 
39
49
  After generating some classes to add relationships to them use the following `YUML::Class` methods.
@@ -17,12 +17,11 @@ module YUML
17
17
  '#' => "\u0023"
18
18
  }
19
19
 
20
- def generate(options)
21
- options = { file: '/tmp/yuml.pdf' }.merge(options)
20
+ def generate(file: '/tmp/yuml.pdf')
22
21
  classes.clear
23
22
  notes.clear
24
23
  yield self
25
- fetch_uml options[:file]
24
+ fetch_uml file
26
25
  end
27
26
 
28
27
  def class(&block)
@@ -32,8 +31,8 @@ module YUML
32
31
  yuml_class
33
32
  end
34
33
 
35
- def attach_note(content, options = {})
36
- notes << YUML::Note.create(content, options)
34
+ def attach_note(content, color = nil)
35
+ notes << YUML::Note.create(content, color)
37
36
  end
38
37
 
39
38
  private
@@ -1,7 +1,7 @@
1
1
  module YUML
2
2
  # Represents a yUML Class
3
3
  class Class
4
- attr_writer :name, :interface
4
+ attr_writer :name
5
5
 
6
6
  def initialize
7
7
  @methods = []
@@ -14,11 +14,18 @@ module YUML
14
14
  "#{normalized_interface}#{@name}"
15
15
  end
16
16
 
17
- def interface(interface = nil)
17
+ def interface(interface = nil, sterotype = 'interface')
18
18
  @interface = interface if interface
19
+ @sterotype = sterotype if interface
19
20
  @interface
20
21
  end
21
22
 
23
+ def interface=(*args)
24
+ args.flatten!
25
+ @interface = args.first
26
+ @sterotype = args.size > 1 ? args.pop : 'interface'
27
+ end
28
+
22
29
  def variables(*args)
23
30
  args.flatten!
24
31
  return attributes(@variables) if args.empty?
@@ -31,28 +38,28 @@ module YUML
31
38
  @methods << normalize(args)
32
39
  end
33
40
 
34
- def has_a(dest, options = {})
35
- options[:type] = :aggregation unless %i(composition aggregation).include?(options[:type])
36
- relationship = YUML::Relationship.send(options[:type], options[:cardinality])
41
+ def has_a(dest, type: :aggregation, cardinality: nil)
42
+ type = :aggregation unless %i(composition aggregation).include?(type)
43
+ relationship = YUML::Relationship.send(type, cardinality)
37
44
  @relationships << "[#{name}]#{relationship}[#{dest.name}]"
38
45
  end
39
46
 
40
- def is_a(dest, options = {})
41
- options[:type] = :inheritance unless %i(inheritance interface).include?(options[:type])
42
- relationship = YUML::Relationship.send(options[:type])
47
+ def is_a(dest, type: :inheritance)
48
+ type = :inheritance unless %i(inheritance interface).include?(type)
49
+ relationship = YUML::Relationship.send(type)
43
50
  @relationships << "[#{dest.name}]#{relationship}[#{name}]"
44
51
  end
45
52
 
46
- def associated_with(dest, options = {})
47
- options[:type] = :directed_assoication unless %i(
53
+ def associated_with(dest, type: :directed_assoication, cardinality: nil)
54
+ type = :directed_assoication unless %i(
48
55
  association directed_assoication two_way_association dependency
49
- ).include?(options[:type])
50
- relationship = YUML::Relationship.send(options[:type], options[:cardinality])
56
+ ).include?(type)
57
+ relationship = YUML::Relationship.send(type, cardinality)
51
58
  @relationships << "[#{name}]#{relationship}[#{dest.name}]"
52
59
  end
53
60
 
54
- def attach_note(content, options = {})
55
- @relationships << "[#{name}]-#{YUML::Note.create(content, options)}"
61
+ def attach_note(content, color = nil)
62
+ @relationships << "[#{name}]-#{YUML::Note.create(content, color)}"
56
63
  end
57
64
 
58
65
  def to_s
@@ -74,7 +81,7 @@ module YUML
74
81
 
75
82
  def normalized_interface
76
83
  name interface unless @name
77
- return normalize(['<<interface>>']).first << ';' if interface
84
+ return normalize(["<<#{@sterotype}>>"]).first << ';' if interface
78
85
  end
79
86
 
80
87
  def attributes(attrs)
@@ -3,9 +3,8 @@ module YUML
3
3
  module Note
4
4
  module_function
5
5
 
6
- def create(body, options = {})
7
- color = options[:color] || 'cornsilk'
8
- "[note: #{body}{bg:#{color}}]"
6
+ def create(body, color = 'cornsilk')
7
+ "[note: #{body}{bg:#{color || 'cornsilk'}}]"
9
8
  end
10
9
  end
11
10
  end
@@ -42,15 +42,31 @@ describe YUML::Class do
42
42
  left = "#{YUML::ESCAPE_CHARACTERS['<']}" * 2
43
43
  right = "#{YUML::ESCAPE_CHARACTERS['>']}" * 2
44
44
  @interface_uml = "[#{left}interface#{right};Document]"
45
+ @module_uml = "[#{left}module#{right};Document]"
45
46
  end
46
- it 'takes a interface and updates the class' do
47
- @uut.interface 'Document'
48
- expect(@uut.to_s).to eq @interface_uml
47
+
48
+ context 'with default sterotype' do
49
+ it 'takes an interface and updates the class' do
50
+ @uut.interface 'Document'
51
+ expect(@uut.to_s).to eq @interface_uml
52
+ end
53
+
54
+ it 'should work with interface=' do
55
+ @uut.interface = 'Document'
56
+ expect(@uut.to_s).to eq @interface_uml
57
+ end
49
58
  end
50
59
 
51
- it 'should work with interface= as well' do
52
- @uut.interface = 'Document'
53
- expect(@uut.to_s).to eq @interface_uml
60
+ context 'with custom sterotype' do
61
+ it 'takes an interface and updates the class' do
62
+ @uut.interface 'Document', 'module'
63
+ expect(@uut.to_s).to eq @module_uml
64
+ end
65
+
66
+ it 'should work with interface=' do
67
+ @uut.interface = 'Document', 'module'
68
+ expect(@uut.to_s).to eq @module_uml
69
+ end
54
70
  end
55
71
  end
56
72
 
@@ -4,7 +4,7 @@ require_relative '../lib/yuml'
4
4
  describe YUML::Note do
5
5
  describe '#create' do
6
6
  it 'should return a formatted string' do
7
- note = YUML::Note.create('This diagram blongs to Derek Stride', color: :green)
7
+ note = YUML::Note.create('This diagram blongs to Derek Stride', :green)
8
8
  expect(note).to eq '[note: This diagram blongs to Derek Stride{bg:green}]'
9
9
  end
10
10
  end
@@ -71,4 +71,10 @@ describe YUML do
71
71
  expect(File.read(@options[:file])).to eq 'abc'
72
72
  end
73
73
  end
74
+
75
+ describe '#attach_note' do
76
+ it 'should work' do
77
+ expect { YUML.attach_note('test', 'green') }.not_to raise_error
78
+ end
79
+ end
74
80
  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.4.0
4
+ version: 0.4.1
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-27 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec