Class: Gotcha::Base
- Inherits:
-
Object
- Object
- Gotcha::Base
- Defined in:
- lib/gotcha/base.rb
Instance Attribute Summary collapse
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
Class Method Summary collapse
-
.down_transform(text) ⇒ Object
A default implementation of down_transform - adds the ability to make transforms fuzzy.
Instance Method Summary collapse
-
#correct?(str) ⇒ Boolean
Determine whether or not an answer is correct.
Instance Attribute Details
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
5 6 7 |
# File 'lib/gotcha/base.rb', line 5 def answer @answer end |
#question ⇒ Object (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
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 |