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.



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

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



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

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

#inspectObject



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

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

#measure(canvas) ⇒ Object



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

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

#sizeObject



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

def size
  options[:font_size] # FIXME
end