mscgen 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README.md +71 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/mscgen.rb +20 -0
- data/lib/mscgen/chart.rb +101 -0
- data/lib/mscgen/entity.rb +25 -0
- data/lib/mscgen/message.rb +49 -0
- data/mscgen.gemspec +66 -0
- data/spec/mscgen_chart_spec.rb +74 -0
- data/spec/mscgen_entity_spec.rb +43 -0
- data/spec/mscgen_message_spec.rb +94 -0
- data/spec/mscgen_spec.rb +12 -0
- data/spec/spec_helper.rb +12 -0
- metadata +113 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "simplecov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.4)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
multi_json (1.0.4)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
simplecov (0.5.4)
|
21
|
+
multi_json (~> 1.0.3)
|
22
|
+
simplecov-html (~> 0.5.3)
|
23
|
+
simplecov-html (0.5.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
jeweler (~> 1.6.4)
|
31
|
+
rspec (~> 2.3.0)
|
32
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Masata NISHIDA
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
mscgen for ruby
|
2
|
+
======================
|
3
|
+
|
4
|
+
[Mscgen](http://www.mcternan.me.uk/mscgen/) is simple sequence chart generator.
|
5
|
+
This gem generates a script for mscgen. This can generate sequence image(i.e. png, svg...) if you set mscgen path.
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
----------
|
9
|
+
### install mscgen
|
10
|
+
|
11
|
+
$ yum install mscgen # Linux(CentOS, Fedora..)
|
12
|
+
$ brew isntall mscgen # MacOS X
|
13
|
+
|
14
|
+
|
15
|
+
Install
|
16
|
+
----------
|
17
|
+
|
18
|
+
$ gem install mscgen
|
19
|
+
|
20
|
+
|
21
|
+
Usage
|
22
|
+
----------
|
23
|
+
### Setting Mscgen Path
|
24
|
+
|
25
|
+
Mscgen.path = '/usr/local/bin/mscgen'
|
26
|
+
|
27
|
+
### Create sequence scripts or images
|
28
|
+
|
29
|
+
require 'mscgen'
|
30
|
+
|
31
|
+
# create chart
|
32
|
+
chart = Mscgen::Chart.new
|
33
|
+
|
34
|
+
# add entities and messages
|
35
|
+
a = chart.add_entity('a')
|
36
|
+
b = chart.add_entity('b')
|
37
|
+
chart.add_message(Mscgen::Message.new(a,b, 'label'))
|
38
|
+
chart.add_message(Mscgen::Message.new(b,a, 'return', :type => :method_return ))
|
39
|
+
|
40
|
+
# create image file
|
41
|
+
chart.to_img('seq.png', :png)
|
42
|
+
|
43
|
+
# or create a script for mscgen
|
44
|
+
script = chart.to_msc
|
45
|
+
File.open('seq.txt', 'w') {|f| f.write script }
|
46
|
+
|
47
|
+
### Support Image Format
|
48
|
+
|
49
|
+
* png
|
50
|
+
* svg
|
51
|
+
* eps
|
52
|
+
* ismap
|
53
|
+
|
54
|
+
refer `mscgen --help`.
|
55
|
+
|
56
|
+
|
57
|
+
Contributing to mscgen
|
58
|
+
----------
|
59
|
+
|
60
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
61
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
62
|
+
* Fork the project
|
63
|
+
* Start a feature/bugfix branch
|
64
|
+
* Commit and push until you are happy with your contribution
|
65
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
66
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
67
|
+
|
68
|
+
Copyright
|
69
|
+
----------
|
70
|
+
Copyright (c) 2012 Masata NISHIDA. See LICENSE.txt for further details.
|
71
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mscgen"
|
18
|
+
gem.homepage = "http://github.com/masatanish/mscgen"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{this gem generates a script for mscgen.}
|
21
|
+
gem.description = %Q{mscgen( http://www.mcternan.me.uk/mscgen/ ) is simple sequence chart generator. this gem generates a script for mscgen.}
|
22
|
+
gem.email = "masatanish@gmail.com"
|
23
|
+
gem.authors = ["Masata NISHIDA"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "mscgen #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/lib/mscgen.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'mscgen/chart')
|
2
|
+
require File.join(File.dirname(__FILE__), 'mscgen/entity')
|
3
|
+
require File.join(File.dirname(__FILE__), 'mscgen/message')
|
4
|
+
|
5
|
+
module Mscgen
|
6
|
+
def self.escape(str)
|
7
|
+
str.gsub(/(["\n])/){ "\\" + $1 }
|
8
|
+
end
|
9
|
+
|
10
|
+
@@mscgen_path = "mscgen"
|
11
|
+
|
12
|
+
# set mscgen command path
|
13
|
+
def self.path=(path)
|
14
|
+
@@mscgen_path = path
|
15
|
+
end
|
16
|
+
# return mscgen command path
|
17
|
+
def self.path
|
18
|
+
@@mscgen_path
|
19
|
+
end
|
20
|
+
end
|
data/lib/mscgen/chart.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Mscgen
|
4
|
+
class Chart
|
5
|
+
|
6
|
+
# sequence chart width
|
7
|
+
attr_accessor :witdh
|
8
|
+
|
9
|
+
# array of Mscgen::Entity
|
10
|
+
attr_reader :entities
|
11
|
+
|
12
|
+
# array of messages
|
13
|
+
attr_reader :messages
|
14
|
+
|
15
|
+
def initialize(width=nil)
|
16
|
+
@entities = []
|
17
|
+
@messages = []
|
18
|
+
@width = width
|
19
|
+
end
|
20
|
+
|
21
|
+
# add entity to chart
|
22
|
+
def add_entity(name)
|
23
|
+
entity = Entity.new(name)
|
24
|
+
@entities << entity
|
25
|
+
return entity
|
26
|
+
end
|
27
|
+
|
28
|
+
# find entity from chart or add entity to chart
|
29
|
+
def find_or_add_entity(name)
|
30
|
+
entity = @entities.find {|e| e.label == name.to_s }
|
31
|
+
if entity.nil?
|
32
|
+
self.add_entity(name)
|
33
|
+
else
|
34
|
+
entity
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# add messages to chart..
|
39
|
+
# _msg_ should respond to 'to_msc'
|
40
|
+
def add_message(msg)
|
41
|
+
raise ArgumentError unless msg.respond_to?(:to_msc)
|
42
|
+
@messages << msg
|
43
|
+
msg
|
44
|
+
end
|
45
|
+
|
46
|
+
# return mscgen format script
|
47
|
+
def to_msc
|
48
|
+
opt = get_opt
|
49
|
+
ent_text = @entities.map{|e| e.to_msc }.join(', ')
|
50
|
+
msg_text = @messages.map{|m| m.to_msc }.join(";\n ")
|
51
|
+
|
52
|
+
return MSC_TEMPLATE % [opt, ent_text, msg_text]
|
53
|
+
end
|
54
|
+
|
55
|
+
# execute mscgen command
|
56
|
+
def to_img(filename, type=nil)
|
57
|
+
text = to_msc()
|
58
|
+
execute_msc_cmd(text, filename, type)
|
59
|
+
text
|
60
|
+
end
|
61
|
+
|
62
|
+
MSC_TEMPLATE = <<-"EOS"
|
63
|
+
# MSC for some fictional process
|
64
|
+
msc {
|
65
|
+
%s
|
66
|
+
|
67
|
+
# entities
|
68
|
+
%s;
|
69
|
+
|
70
|
+
# messages
|
71
|
+
%s;
|
72
|
+
}
|
73
|
+
EOS
|
74
|
+
|
75
|
+
def get_opt # :nodoc:
|
76
|
+
unless @width.nil?
|
77
|
+
"width=#{@width};"
|
78
|
+
else
|
79
|
+
""
|
80
|
+
end
|
81
|
+
end
|
82
|
+
private :get_opt
|
83
|
+
|
84
|
+
FILE_TYPE = { # :nodoc:
|
85
|
+
:png => "png",
|
86
|
+
:svg => "svg",
|
87
|
+
:eps => "eps",
|
88
|
+
:ismap => "ismap",
|
89
|
+
}
|
90
|
+
def execute_msc_cmd(text, filename, type=nil) # :nodoc:
|
91
|
+
f = Tempfile.new('mscgen')
|
92
|
+
f.write(text)
|
93
|
+
f.close
|
94
|
+
type_str = FILE_TYPE.fetch(type, "png")
|
95
|
+
system("#{Mscgen.path} -T #{type_str} -o #{filename} -i #{f.path}")
|
96
|
+
ensure
|
97
|
+
f.close(true) # delete temporary file
|
98
|
+
end
|
99
|
+
private :execute_msc_cmd
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mscgen
|
2
|
+
# sequence entity object
|
3
|
+
class Entity
|
4
|
+
@@entity_count = 0
|
5
|
+
|
6
|
+
# entity label
|
7
|
+
attr_accessor:label
|
8
|
+
|
9
|
+
def initialize(label)
|
10
|
+
@label = Mscgen.escape(label.to_s)
|
11
|
+
@eid = @@entity_count
|
12
|
+
@@entity_count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
# return entity name
|
16
|
+
def name
|
17
|
+
"ent_#{@eid}"
|
18
|
+
end
|
19
|
+
|
20
|
+
# retrun mscgen format text
|
21
|
+
def to_msc
|
22
|
+
"#{name}[label=\"#{@label}\"]"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Mscgen
|
2
|
+
class Message
|
3
|
+
ALLOW_TYPE = {
|
4
|
+
:messege => "->",
|
5
|
+
:method => "=>",
|
6
|
+
:method_return => ">>",
|
7
|
+
:callback => "=>>",
|
8
|
+
:emph_message => ":>",
|
9
|
+
:lost_message => "-x",
|
10
|
+
}
|
11
|
+
|
12
|
+
attr_reader :label, :from, :to
|
13
|
+
|
14
|
+
# from
|
15
|
+
# option supports :type, :linecolor, :textcolor attributes
|
16
|
+
def initialize(from, to, label=nil, option={})
|
17
|
+
@from = from
|
18
|
+
@to = to
|
19
|
+
@label = Mscgen.escape(label.to_s) unless label.nil?
|
20
|
+
@options = option
|
21
|
+
end
|
22
|
+
|
23
|
+
# return mscgen format text
|
24
|
+
def to_msc
|
25
|
+
message = "#{@from.name} #{allow} #{@to.name}"
|
26
|
+
message += option_string
|
27
|
+
message
|
28
|
+
end
|
29
|
+
|
30
|
+
def option_string # :nodoc:
|
31
|
+
opt_arr = []
|
32
|
+
opt_arr << "label=\"#{@label}\"" if @label
|
33
|
+
opt_arr << "linecolor=\"#{@options[:linecolor]}\"" if @options[:linecolor]
|
34
|
+
opt_arr << "textcolor=\"#{@options[:textcolor]}\"" if @options[:textcolor]
|
35
|
+
if opt_arr.size > 0
|
36
|
+
"[ #{opt_arr.join(", ")} ]"
|
37
|
+
else
|
38
|
+
""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
protected :option_string
|
42
|
+
|
43
|
+
# determine allow shape
|
44
|
+
def allow # :nodoc:
|
45
|
+
ALLOW_TYPE.fetch(@options[:type], "->")
|
46
|
+
end
|
47
|
+
protected :allow
|
48
|
+
end
|
49
|
+
end
|
data/mscgen.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "mscgen"
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Masata NISHIDA"]
|
12
|
+
s.date = "2012-02-13"
|
13
|
+
s.description = "mscgen( http://www.mcternan.me.uk/mscgen/ ) is simple sequence chart generator. this gem generates a script for mscgen."
|
14
|
+
s.email = "masatanish@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/mscgen.rb",
|
29
|
+
"lib/mscgen/chart.rb",
|
30
|
+
"lib/mscgen/entity.rb",
|
31
|
+
"lib/mscgen/message.rb",
|
32
|
+
"mscgen.gemspec",
|
33
|
+
"spec/mscgen_chart_spec.rb",
|
34
|
+
"spec/mscgen_entity_spec.rb",
|
35
|
+
"spec/mscgen_message_spec.rb",
|
36
|
+
"spec/mscgen_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/masatanish/mscgen"
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "1.8.15"
|
43
|
+
s.summary = "this gem generates a script for mscgen."
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
52
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
57
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mscgen::Chart do
|
4
|
+
before do
|
5
|
+
@chart = Mscgen::Chart .new
|
6
|
+
end
|
7
|
+
describe "#add_entity" do
|
8
|
+
before do
|
9
|
+
@name = 'foo'
|
10
|
+
end
|
11
|
+
subject { @chart.add_entity(@name) }
|
12
|
+
it "should add Chart.entities" do
|
13
|
+
lambda { @chart.add_entity('foo') }.should change(@chart.entities, :size).by(1)
|
14
|
+
end
|
15
|
+
it { should be_kind_of(Mscgen::Entity) }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#find_or_add_entity" do
|
19
|
+
subject { @chart.find_or_add_entity(@name) }
|
20
|
+
context "when input new entity name" do
|
21
|
+
it { should be_kind_of(Mscgen::Entity) }
|
22
|
+
it "should add new Entity to Chart.entities" do
|
23
|
+
lambda { subject }.should change(@chart.entities, :size).by(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when input exist entity name" do
|
28
|
+
before do
|
29
|
+
# create @name entitiy
|
30
|
+
@exist_entity = @chart.add_entity(@name)
|
31
|
+
end
|
32
|
+
it { should be_kind_of(Mscgen::Entity) }
|
33
|
+
it "should return exist entity" do
|
34
|
+
should equal @exist_entity
|
35
|
+
end
|
36
|
+
it "should not change Chart.entities" do
|
37
|
+
lambda { subject }.should_not change(@chart.entities, :count)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#add_message" do
|
43
|
+
before do
|
44
|
+
@ent1 = @chart.add_entity('a')
|
45
|
+
@ent2 = @chart.add_entity('b')
|
46
|
+
end
|
47
|
+
subject { @chart.add_message(@msg) }
|
48
|
+
context "with not Message object" do
|
49
|
+
before do
|
50
|
+
@msg = "aaa"
|
51
|
+
end
|
52
|
+
it do
|
53
|
+
lambda {subject}.should raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
context "with Message object" do
|
57
|
+
before do
|
58
|
+
@msg = Mscgen::Message.new(@ent1, @ent2, 'foobar')
|
59
|
+
end
|
60
|
+
it { should be_kind_of(Mscgen::Message) }
|
61
|
+
it do
|
62
|
+
lambda {subject}.should change(@chart.messages, :size).by(1)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#to_msc" do
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#to_img" do
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mscgen::Entity do
|
4
|
+
before do
|
5
|
+
@label = "entity_label"
|
6
|
+
@entity = Mscgen::Entity.new("entity_label")
|
7
|
+
end
|
8
|
+
subject { @entity }
|
9
|
+
describe "#new" do
|
10
|
+
it { should be_kind_of(Mscgen::Entity) }
|
11
|
+
it "label should be set" do
|
12
|
+
subject.label.should == "entity_label"
|
13
|
+
end
|
14
|
+
it "should have unique id" do
|
15
|
+
entity = Mscgen::Entity.new("label")
|
16
|
+
entity.name.should_not eq @entity.name
|
17
|
+
entity = Mscgen::Entity.new("label")
|
18
|
+
entity.name.should_not eq @entity.name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#label=" do
|
23
|
+
it do
|
24
|
+
lambda {
|
25
|
+
@entity.label = "label2"
|
26
|
+
}.should change(@entity, :label).from("entity_label").to("label2")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe "#label" do
|
30
|
+
it { subject.label.should eq "entity_label" }
|
31
|
+
it "should escape special chars" do
|
32
|
+
@entity.label = 'abcabc\"'
|
33
|
+
@entity.label.should eq 'abcabc\"'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe "#name" do
|
37
|
+
it { subject.name.should match(/ent_\d+/) }
|
38
|
+
end
|
39
|
+
describe "#to_msc" do
|
40
|
+
it { subject.to_msc.should match(/ent_\d+\[label=\"#{@label}\"\]/) }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mscgen::Message do
|
4
|
+
before do
|
5
|
+
@ent1 = Mscgen::Entity.new('abc')
|
6
|
+
@ent2 = Mscgen::Entity.new('def')
|
7
|
+
@label = "label_str"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#initialize" do
|
11
|
+
subject { Mscgen::Message.new(@ent1, @ent2, @label) }
|
12
|
+
it { should be_kind_of(Mscgen::Message) }
|
13
|
+
end
|
14
|
+
describe "#from" do
|
15
|
+
subject { Mscgen::Message.new(@ent1, @ent2, "abc").from }
|
16
|
+
it { should equal @ent1 }
|
17
|
+
end
|
18
|
+
describe "#to" do
|
19
|
+
subject { Mscgen::Message.new(@ent1, @ent2, "abc").to }
|
20
|
+
it { should equal @ent2 }
|
21
|
+
end
|
22
|
+
describe "#label" do
|
23
|
+
subject { Mscgen::Message.new(@ent1, @ent2, @label).label }
|
24
|
+
it { should eq @label }
|
25
|
+
context "when label string includes special charactor" do
|
26
|
+
it "should escape special char" do
|
27
|
+
@label = 'abcabc"abc'
|
28
|
+
subject.should eq 'abcabc\"abc'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_msc" do
|
34
|
+
subject { Mscgen::Message.new(@ent1, @ent2, @label, @option).to_msc }
|
35
|
+
context "with no label and no options" do
|
36
|
+
before do
|
37
|
+
@label = nil
|
38
|
+
@option = {}
|
39
|
+
end
|
40
|
+
it { should == "#{@ent1.name} -> #{@ent2.name}" }
|
41
|
+
end
|
42
|
+
context "with label string and no options" do
|
43
|
+
before do
|
44
|
+
@label = "foo"
|
45
|
+
@option = {}
|
46
|
+
end
|
47
|
+
it { should == "#{@ent1.name} -> #{@ent2.name}[ label=\"foo\" ]" }
|
48
|
+
end
|
49
|
+
context "with option { :type => :method }" do
|
50
|
+
before do
|
51
|
+
@label = "foo"
|
52
|
+
@option = {:type => :method }
|
53
|
+
end
|
54
|
+
it { should == "#{@ent1.name} => #{@ent2.name}[ label=\"foo\" ]" }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#option_string" do
|
59
|
+
subject { Mscgen::Message.new(@ent1, @ent2, @label, @option).send(:option_string) }
|
60
|
+
context "only label" do
|
61
|
+
before do
|
62
|
+
@label = "abcabc"
|
63
|
+
@option = {}
|
64
|
+
end
|
65
|
+
it { should == "[ label=\"abcabc\" ]" }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with label and option{:linecolor => '#ff0000'}" do
|
69
|
+
before do
|
70
|
+
@label = "abcabc"
|
71
|
+
@option = {:linecolor => '#ff0000' }
|
72
|
+
end
|
73
|
+
it { should == "[ label=\"abcabc\", linecolor=\"#ff0000\" ]" }
|
74
|
+
end
|
75
|
+
context "with label and option{:linecolor => '#ff0000', :textcolor => '#00ff00' }" do
|
76
|
+
before do
|
77
|
+
@label = "abcabc"
|
78
|
+
@option = {:linecolor => '#ff0000', :textcolor => '#00ff00' }
|
79
|
+
end
|
80
|
+
it { should == "[ label=\"abcabc\", linecolor=\"#ff0000\", textcolor=\"#00ff00\" ]" }
|
81
|
+
end
|
82
|
+
|
83
|
+
context "with unknown options" do
|
84
|
+
before do
|
85
|
+
@label = "abcabc"
|
86
|
+
@option = {:foo => 'abc', :linecolor => '#ff0000' }
|
87
|
+
end
|
88
|
+
it "should ignore unknown options" do
|
89
|
+
subject.should == "[ label=\"abcabc\", linecolor=\"#ff0000\" ]"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
data/spec/mscgen_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Mscgen" do
|
4
|
+
describe "#escape" do
|
5
|
+
it "should escape '\"'" do
|
6
|
+
Mscgen.escape('abc"abc').should == 'abc\"abc'
|
7
|
+
end
|
8
|
+
it "should escape '\\n'" do
|
9
|
+
Mscgen.escape("abc\nabc").should == "abc\\\nabc"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mscgen'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mscgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Masata NISHIDA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70098992503940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70098992503940
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &70098992503460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70098992503460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &70098992502980 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.4
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70098992502980
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: &70098992539340 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70098992539340
|
58
|
+
description: mscgen( http://www.mcternan.me.uk/mscgen/ ) is simple sequence chart
|
59
|
+
generator. this gem generates a script for mscgen.
|
60
|
+
email: masatanish@gmail.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
files:
|
67
|
+
- .document
|
68
|
+
- .rspec
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- VERSION
|
75
|
+
- lib/mscgen.rb
|
76
|
+
- lib/mscgen/chart.rb
|
77
|
+
- lib/mscgen/entity.rb
|
78
|
+
- lib/mscgen/message.rb
|
79
|
+
- mscgen.gemspec
|
80
|
+
- spec/mscgen_chart_spec.rb
|
81
|
+
- spec/mscgen_entity_spec.rb
|
82
|
+
- spec/mscgen_message_spec.rb
|
83
|
+
- spec/mscgen_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: http://github.com/masatanish/mscgen
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -3737380167972180771
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.15
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: this gem generates a script for mscgen.
|
113
|
+
test_files: []
|