Class: Hanuman::Graphvizzer::Node

Inherits:
Item
  • Object
show all
Defined in:
lib/hanuman/graphvizzer/gv_models.rb

Instance Method Summary collapse

Methods inherited from Item

#attrib, #brace, #close_brace, #depth, #indent, #line, #quote

Instance Method Details

#abbreviate(word) ⇒ Object



120
121
122
123
124
125
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 120

def abbreviate(word)
  word.to_s.
    gsub(/-\d+$/,'').   # remove a trailing index (-0...)
    split(/[\W_]+/).    # split into _ separated segment
    reject(&:empty?).map{|str| str[0] }.join
end

#inslots_strObject



127
128
129
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 127

def inslots_str
  inslots.map{|slot|  "<#{slot}>#{abbreviate(slot)}"}.join("|")
end

#labelObject



135
136
137
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 135

def label
  super.to_s.gsub(/_\d+$/, '').gsub(/[_\.]+/, "\\n")
end

#outslots_strObject



131
132
133
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 131

def outslots_str
  outslots.map{|slot| "<_#{slot}>#{abbreviate(slot)}"}.join("|")
end

#structured_labelObject



139
140
141
142
143
144
145
146
147
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 139

def structured_label
  return label unless shape =~ /record/
  str = "{"
  str << "{"  << (inslots.empty?  ? "<i>"  : inslots_str) << "}|"
  str << label
  str << "|{" << (outslots.empty? ? "<_o>" : outslots_str) << "}"
  str << "}"
  str
end

#to_sObject



112
113
114
115
116
117
118
# File 'lib/hanuman/graphvizzer/gv_models.rb', line 112

def to_s
  line(
    quote(name),                            ## "cherry_pie.crust.small_bowl"      [
    :shape => shape,                        ##   shape=Mrecord,
    :label => quote(structured_label),      ##   label="{{<in>sb}|small\nbowl}"
    )                                       ## ];
end