Class: Rubigraph::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/rubigraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil) ⇒ Vertex

Returns a new instance of Vertex.



16
17
18
19
20
21
# File 'lib/rubigraph.rb', line 16

def initialize(id = nil)
  @id = id ?
    Rubigraph.call('ubigraph.new_vertex_w_id', id) :
    Rubigraph.call('ubigraph.new_vertex')
  raise 'Rubigraph::Vertex.initialize: cannot create vertex' if @id == -1
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/rubigraph.rb', line 14

def id
  @id
end

Instance Method Details

#color=(c) ⇒ Object



39
40
41
# File 'lib/rubigraph.rb', line 39

def color=(c)
  set_attribute('color', c)
end

#colour=(c) ⇒ Object



43
44
45
# File 'lib/rubigraph.rb', line 43

def colour=(c)
  self.color=(c)
end

#fontcolor=(c) ⇒ Object



67
68
69
# File 'lib/rubigraph.rb', line 67

def fontcolor=(c)
  set_attribute('fontcolor', c)
end

#fontfamily=(f) ⇒ Object



71
72
73
74
# File 'lib/rubigraph.rb', line 71

def fontfamily=(f)
  # TODO: should assert 'Helvetica' | 'Times Roman'
  set_attribute('fontfamily', f)
end

#fontsize=(s) ⇒ Object



76
77
78
79
# File 'lib/rubigraph.rb', line 76

def fontsize=(s)
  # TODO: should assert 10, 12, 18. 24
  set_attribute('fontsize', s)
end

#label=(l) ⇒ Object



55
56
57
# File 'lib/rubigraph.rb', line 55

def label=(l)
  set_attribute('label', l)
end

#labelpos=(p) ⇒ Object



59
60
61
# File 'lib/rubigraph.rb', line 59

def labelpos=(p)
  set_attribute('labelpos', p)
end

#removeObject



23
24
25
26
27
# File 'lib/rubigraph.rb', line 23

def remove
  if -1 == Rubigraph.call('ubigraph.remove_vertex', @id)
    raise "Rubigraph::Vertex#remove: cannot remove vertex #{@id}"
  end
end

#set_attribute(att, value) ⇒ Object



29
30
31
# File 'lib/rubigraph.rb', line 29

def set_attribute(att, value)
  Rubigraph.call('ubigraph.set_vertex_attribute', @id, att, value.to_s)
end

#set_attributes(attrs) ⇒ Object



33
34
35
36
37
# File 'lib/rubigraph.rb', line 33

def set_attributes(attrs)
  attrs.each do |k, v|
    Rubigraph.call('ubigraph.set_vertex_attribute', @id, k, v.to_s)
  end
end

#shape=(s) ⇒ Object



47
48
49
# File 'lib/rubigraph.rb', line 47

def shape=(s)
  set_attribute('shape', s)
end

#shapedetail=(d) ⇒ Object



51
52
53
# File 'lib/rubigraph.rb', line 51

def shapedetail=(d)
  set_attribute('shapedetail', d)
end

#size=(s) ⇒ Object



63
64
65
# File 'lib/rubigraph.rb', line 63

def size=(s)
  set_attribute('size', s)
end