Class: Rviz::Record

Inherits:
Node
  • Object
show all
Defined in:
lib/rviz/record.rb

Direct Known Subclasses

Mrecord

Instance Attribute Summary

Attributes inherited from Node

#name

Instance Method Summary collapse

Methods inherited from Node

#shape

Methods included from Helper

#attrs_to_s, #quote, #set

Constructor Details

#initialize(name, attrs = {}) ⇒ Record

Returns a new instance of Record.



3
4
5
6
7
# File 'lib/rviz/record.rb', line 3

def initialize name, attrs = {}
  super name, "record", attrs
  @label_rows = Array.new
  @anchors = Hash.new
end

Instance Method Details

#add_row(row_name, create_anchor = false, port_pos = 'n') ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rviz/record.rb', line 19

def add_row row_name, create_anchor = false, port_pos = 'n'
  if create_anchor 
    anchor_id = @anchors.keys.size + 1
    @anchors[row_name] = anchor_id
    row_name.gsub!(/([\/\|\\\<\>])/, '-') # escape special characters
    row_name = "<f#{anchor_id.to_s}>" + row_name
  end
  if port_pos
    raise "unknown port_pos, should in l, r or n" unless %w[l r n].include? port_pos
  end
  @label_rows << [row_name, port_pos]
  self
end

#get_anchor(row_name) ⇒ Object

get the anchor name used for edge link



15
16
17
# File 'lib/rviz/record.rb', line 15

def get_anchor row_name
  "f" + self.get_anchor_id(row_name).to_s if get_anchor_id(row_name)
end

#get_anchor_id(row_name) ⇒ Object

from row_name returns the id corresponds to the anchor



10
11
12
# File 'lib/rviz/record.rb', line 10

def get_anchor_id row_name
  @anchors[row_name]
end

#label_with_rowsObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/rviz/record.rb', line 33

def label_with_rows
  labels = Array.new
  i =0
  @label_rows.each do |a|
    str, lr = a[0], a[1]
    str += " \\" + lr if %w[l r].include? lr
    labels << str
  end
  labels.join('|')
end

#to_sObject



44
45
46
47
# File 'lib/rviz/record.rb', line 44

def to_s
  @attrs['label'] = self.label_with_rows
  super
end