Class: Playmo::Answer

Inherits:
Object show all
Defined in:
lib/playmo/answer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(answer, options, num, &block) ⇒ Answer

Returns a new instance of Answer.



5
6
7
8
9
10
11
# File 'lib/playmo/answer.rb', line 5

def initialize(answer, options, num, &block)
  @answer  = answer
  @options = options
  @num     = num
  @block   = block
  @color   = Thor::Shell::Color.new
end

Instance Attribute Details

#answerObject

Returns the value of attribute answer.



3
4
5
# File 'lib/playmo/answer.rb', line 3

def answer
  @answer
end

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/playmo/answer.rb', line 3

def block
  @block
end

#colorObject

Returns the value of attribute color.



3
4
5
# File 'lib/playmo/answer.rb', line 3

def color
  @color
end

#numObject

Returns the value of attribute num.



3
4
5
# File 'lib/playmo/answer.rb', line 3

def num
  @num
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/playmo/answer.rb', line 3

def options
  @options
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/playmo/answer.rb', line 13

def default?
  options.try(:[], :default) == true
end

#renderObject Also known as: to_s



17
18
19
20
21
22
23
# File 'lib/playmo/answer.rb', line 17

def render
  if @answer
    result = color.set_color("#{@num}. #{@answer}", :white, true)
    result << " (default)" if default?
    result
  end
end