Class: Mscgen::Chart
- Inherits:
-
Object
- Object
- Mscgen::Chart
- Defined in:
- lib/mscgen/chart.rb
Constant Summary collapse
- MSC_TEMPLATE =
<<-"EOS" # MSC for some fictional process msc { %s # entities %s; # messages %s; } EOS
- FILE_TYPE =
:nodoc:
{ # :nodoc: :png => "png", :svg => "svg", :eps => "eps", :ismap => "ismap", }
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
array of Mscgen::Entity.
-
#messages ⇒ Object
readonly
array of messages.
-
#witdh ⇒ Object
sequence chart width.
Instance Method Summary collapse
-
#add_entity(name) ⇒ Object
add entity to chart.
-
#add_message(from_or_msg, to = nil, label = nil, param = nil) ⇒ Object
add messages to chart..
-
#find_or_add_entity(name) ⇒ Object
find entity from chart or add entity to chart.
-
#initialize(width = nil) ⇒ Chart
constructor
A new instance of Chart.
-
#to_img(filename, type = nil) ⇒ Object
execute mscgen command.
-
#to_msc ⇒ Object
return mscgen format script.
Constructor Details
#initialize(width = nil) ⇒ Chart
Returns a new instance of Chart.
15 16 17 18 19 |
# File 'lib/mscgen/chart.rb', line 15 def initialize(width=nil) @entities = [] @messages = [] @width = width end |
Instance Attribute Details
#entities ⇒ Object (readonly)
array of Mscgen::Entity
10 11 12 |
# File 'lib/mscgen/chart.rb', line 10 def entities @entities end |
#messages ⇒ Object (readonly)
array of messages
13 14 15 |
# File 'lib/mscgen/chart.rb', line 13 def @messages end |
#witdh ⇒ Object
sequence chart width
7 8 9 |
# File 'lib/mscgen/chart.rb', line 7 def witdh @witdh end |
Instance Method Details
#add_entity(name) ⇒ Object
add entity to chart
22 23 24 25 26 |
# File 'lib/mscgen/chart.rb', line 22 def add_entity(name) entity = Entity.new(name) @entities << entity return entity end |
#add_message(from_or_msg, to = nil, label = nil, param = nil) ⇒ Object
add messages to chart..
- from_or_msg
-
from entity or Message instance
- to
-
to entity
- label
-
message label string
- param
-
message parameters
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mscgen/chart.rb', line 43 def (from_or_msg, to=nil, label=nil, param=nil) if to.nil? and label.nil? and param.nil? msg = from_or_msg raise ArgumentError unless msg.respond_to?(:to_msc) else msg = Mscgen::Message.new(from_or_msg, to, label, param) end @messages << msg msg end |
#find_or_add_entity(name) ⇒ Object
find entity from chart or add entity to chart
29 30 31 32 33 34 35 36 |
# File 'lib/mscgen/chart.rb', line 29 def find_or_add_entity(name) entity = @entities.find {|e| e.label == name.to_s } if entity.nil? self.add_entity(name) else entity end end |
#to_img(filename, type = nil) ⇒ Object
execute mscgen command
64 65 66 67 68 |
# File 'lib/mscgen/chart.rb', line 64 def to_img(filename, type=nil) text = to_msc() execute_msc_cmd(text, filename, type) text end |
#to_msc ⇒ Object
return mscgen format script
55 56 57 58 59 60 61 |
# File 'lib/mscgen/chart.rb', line 55 def to_msc opt = get_opt ent_text = @entities.map{|e| e.to_msc }.join(', ') msg_text = @messages.map{|m| m.to_msc }.join(";\n ") return MSC_TEMPLATE % [opt, ent_text, msg_text] end |