Class: Pimento::Component

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/pimento/component.rb

Constant Summary collapse

@@klasses =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#render

Constructor Details

#initialize(canvas, x, y) ⇒ Component

Returns a new instance of Component.



22
23
24
25
26
# File 'lib/pimento/component.rb', line 22

def initialize(canvas, x, y)
  @x = x
  @y = y
  @canvas = canvas
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



5
6
7
# File 'lib/pimento/component.rb', line 5

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



5
6
7
# File 'lib/pimento/component.rb', line 5

def y
  @y
end

Class Method Details

.for(type) ⇒ Object



17
18
19
# File 'lib/pimento/component.rb', line 17

def for(type)
  @@klasses[type][rand(@@klasses[type].length)]
end

.handles(*types) ⇒ Object



10
11
12
13
14
15
# File 'lib/pimento/component.rb', line 10

def handles(*types)
  types.each do |type|
    @@klasses[type] ||= []
    @@klasses[type] << self
  end
end

Instance Method Details

#num_objectsObject



28
29
30
# File 'lib/pimento/component.rb', line 28

def num_objects
  2
end

#render_object(id_offset) ⇒ Object



32
33
34
# File 'lib/pimento/component.rb', line 32

def render_object(id_offset)
  render(template_name('ro'), :id_offset => id_offset).to_s
end

#render_object_record(id_offset, obj_offset) ⇒ Object



36
37
38
# File 'lib/pimento/component.rb', line 36

def render_object_record(id_offset, obj_offset)
  render('or_%i' % num_objects, :id_offset => id_offset, :obj_offset => obj_offset).to_s
end

#template_name(suffix) ⇒ Object



40
41
42
43
# File 'lib/pimento/component.rb', line 40

def template_name(suffix)
  basename = Util.underscore(self.class.to_s.split(/::/).last)
  [basename, suffix].join('_')
end