Class: Xsay::Render

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(colour: options[:colour].to_sym, distance: options[:distance], speed: options[:speed]) ⇒ Render

Returns a new instance of Render.



5
6
7
8
9
10
11
12
13
# File 'lib/xsay/render.rb', line 5

def initialize(
  colour: options[:colour].to_sym,
  distance: options[:distance],
  speed: options[:speed]
)
  @colour = colour.to_sym
  @distance = distance
  @speed = speed
end

Instance Attribute Details

#colourObject (readonly)

Returns the value of attribute colour.



3
4
5
# File 'lib/xsay/render.rb', line 3

def colour
  @colour
end

#distanceObject (readonly)

Returns the value of attribute distance.



3
4
5
# File 'lib/xsay/render.rb', line 3

def distance
  @distance
end

#speedObject (readonly)

Returns the value of attribute speed.



3
4
5
# File 'lib/xsay/render.rb', line 3

def speed
  @speed
end

Instance Method Details

#each_frameObject



24
25
26
27
28
# File 'lib/xsay/render.rb', line 24

def each_frame
  return yield 0 unless move?
  frames = distance.downto(0).to_a + 0.upto(distance).to_a
  frames.each { |x| yield x }
end

#render(message, template) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/xsay/render.rb', line 15

def render(message, template)
  message = message.join(' ') if message.respond_to?(:join)
  line_break = "-" * message.length
  each_frame do |frame|
    draw(message, template, line_break, frame)
  end
  nil
end