Class: Gotcha::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gotcha/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



5
6
7
# File 'lib/gotcha/base.rb', line 5

def answer
  @answer
end

#questionObject (readonly)

Returns the value of attribute question.



5
6
7
# File 'lib/gotcha/base.rb', line 5

def question
  @question
end

Class Method Details

.down_transform(text) ⇒ Object

A default implementation of down_transform - adds the ability to make transforms fuzzy



14
15
16
17
18
19
20
# File 'lib/gotcha/base.rb', line 14

def self.down_transform(text)
  text = text.is_a?(String) ? text.dup : text.to_s
  text.downcase!
  text.gsub! /\s+/, ' '
  text.strip!
  text
end

Instance Method Details

#correct?(str) ⇒ Boolean

Determine whether or not an answer is correct

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/gotcha/base.rb', line 8

def correct?(str)
  str = str.is_a?(String) ? str : str.to_s
  str == (@answer.is_a?(String) ? @answer : @answer.to_s) # don't change @answer type
end