Class: MagicCloud::Word

Inherits:
Shape
  • Object
show all
Defined in:
lib/magic_cloud/word.rb

Overview

Class representing individual word in word cloud

Instance Attribute Summary collapse

Attributes inherited from Shape

#height, #rect, #sprite, #width, #x, #y

Instance Method Summary collapse

Methods inherited from Shape

#bottom, #left, #right, #top

Constructor Details

#initialize(text, options) ⇒ Word

Returns a new instance of Word.



8
9
10
11
# File 'lib/magic_cloud/word.rb', line 8

def initialize(text, options)
  super()
  @text, @options = text.to_s, options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/magic_cloud/word.rb', line 13

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



13
14
15
# File 'lib/magic_cloud/word.rb', line 13

def text
  @text
end

Instance Method Details

#draw(canvas, opts = {}) ⇒ Object



19
20
21
# File 'lib/magic_cloud/word.rb', line 19

def draw(canvas, opts = {})
  canvas.draw_text(text, @options.merge(x: x, y: y).merge(opts))
end

#inspectObject



27
28
29
# File 'lib/magic_cloud/word.rb', line 27

def inspect
  "#<#{self.class} #{text}:#{options}>"
end

#measure(canvas) ⇒ Object



23
24
25
# File 'lib/magic_cloud/word.rb', line 23

def measure(canvas)
  canvas.measure_text(text, @options)
end

#sizeObject



15
16
17
# File 'lib/magic_cloud/word.rb', line 15

def size
  options[:font_size] # FIXME
end