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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yuml.rb +74 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 508fdebd5e20dd067d21bc3172fb3e4d9c3c0f17
4
- data.tar.gz: 12bb3693b5dfadcf8fa497edb035d20afe6913d9
3
+ metadata.gz: d26bbbcd5645713f0d95dd6e418fd6fe1acc617f
4
+ data.tar.gz: a17b1a05f2602551c70f5f94c2d49e472d70b4c7
5
5
  SHA512:
6
- metadata.gz: 6ff3c8a87b37206505f1ae58b1ad54f6eaaff440b48988218f0ad215f1ba6f693f3ec06f2e8b23f4fa37bb7b27bea600579ea7cbbb0322008a0991dbc59ba843
7
- data.tar.gz: ff31268654ebcfa26f32a8208fb75a090bec511f2c4f662745fc3ec7ace043e612d83b93a029652d9b5948116ecde73ea746989c90aa9a6536d8ff16d98e9ce9
6
+ metadata.gz: 81a3897f59e805c8bc2ba41c3e1f4dc1f5acde251084c541a9324273bab5871a4a9ea51a30e7c7083d8ab347232910ab99d29a7158e89ae1aed7d9000525dc24
7
+ data.tar.gz: f5ffcb9409a70ce29144d6968b1cbf9613f00a5d91567f31c4e318586fcffcc27201c9f7c4680dd9194aa6eaaff04d0b3c8e24f5eb2b445a05c4dc22b8acefda
@@ -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
- def generate_class
7
- y = YUML::Class.new
8
- yield y
9
- y
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
- module_function :generate_class
81
+ doc.has_a(pic)
13
82
  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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Stride