yuml 0.1.0 → 0.2.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 +4 -4
- data/lib/yuml.rb +74 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d26bbbcd5645713f0d95dd6e418fd6fe1acc617f
|
4
|
+
data.tar.gz: a17b1a05f2602551c70f5f94c2d49e472d70b4c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81a3897f59e805c8bc2ba41c3e1f4dc1f5acde251084c541a9324273bab5871a4a9ea51a30e7c7083d8ab347232910ab99d29a7158e89ae1aed7d9000525dc24
|
7
|
+
data.tar.gz: f5ffcb9409a70ce29144d6968b1cbf9613f00a5d91567f31c4e318586fcffcc27201c9f7c4680dd9194aa6eaaff04d0b3c8e24f5eb2b445a05c4dc22b8acefda
|
data/lib/yuml.rb
CHANGED
@@ -1,13 +1,82 @@
|
|
1
1
|
# Fetches UML from yUML
|
2
|
+
require 'net/http'
|
2
3
|
require_relative 'yuml/class'
|
3
4
|
require_relative 'yuml/relationship'
|
4
5
|
|
5
6
|
module YUML
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
extend self
|
8
|
+
|
9
|
+
ESCAPE_CHARACTERS = {
|
10
|
+
'{' => "\u23A8",
|
11
|
+
'}' => "\u23AC"
|
12
|
+
}
|
13
|
+
|
14
|
+
ESCAPE_COMMA = "\u201A"
|
15
|
+
|
16
|
+
def generate(options)
|
17
|
+
options = { file: '/tmp/yuml.pdf' }.merge(options)
|
18
|
+
classes.clear
|
19
|
+
yield self
|
20
|
+
fetch_uml options[:file]
|
21
|
+
end
|
22
|
+
|
23
|
+
def class(&block)
|
24
|
+
yuml_class = YUML::Class.new
|
25
|
+
block.arity < 1 ? yuml_class.instance_eval(&block) : block.call(yuml_class)
|
26
|
+
classes << yuml_class
|
27
|
+
yuml_class
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def classes
|
33
|
+
@classes ||= []
|
34
|
+
end
|
35
|
+
|
36
|
+
def yuml
|
37
|
+
uml = classes.map(&:to_s).join(',')
|
38
|
+
relationships = classes.map(&:relationships).compact
|
39
|
+
uml << ',' << relationships.join(',') unless relationships.empty?
|
40
|
+
puts uml
|
41
|
+
URI.encode(uml, encodings)
|
42
|
+
end
|
43
|
+
|
44
|
+
def fetch_uml(file)
|
45
|
+
uri = URI("http://yuml.me/diagram/class/#{yuml}.pdf")
|
46
|
+
response = Net::HTTP.get_response(uri)
|
47
|
+
File.write(file, response.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
def encodings
|
51
|
+
"#{ESCAPE_CHARACTERS.values.join}#{ESCAPE_COMMA}[](){}+->|,=;* "
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
YUML.generate(file: 'tmp.pdf') do |uml|
|
56
|
+
doc = uml.class do
|
57
|
+
name 'Document'
|
58
|
+
end
|
59
|
+
|
60
|
+
pic = uml.class do
|
61
|
+
name 'Picture'
|
62
|
+
public_methods :foo
|
63
|
+
end
|
64
|
+
|
65
|
+
doc.has_a(pic)
|
66
|
+
end
|
67
|
+
|
68
|
+
YUML.generate(file: 'tmp2.pdf') do |uml|
|
69
|
+
doc = uml.class do
|
70
|
+
name 'Document'
|
71
|
+
end
|
72
|
+
|
73
|
+
pic = uml.class do
|
74
|
+
name 'Picture'
|
75
|
+
public_variables :fizz
|
76
|
+
private_variables :buzz
|
77
|
+
public_methods(foo: [:bar])
|
78
|
+
private_methods(baz: ['arg = nil', 'param = {}', '*args'], lam: [:star])
|
10
79
|
end
|
11
80
|
|
12
|
-
|
81
|
+
doc.has_a(pic)
|
13
82
|
end
|