Class: Word
- Inherits:
-
Object
- Object
- Word
- Defined in:
- lib/learn_words.rb
Overview
READING WORDS FILE
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#orig ⇒ Object
readonly
Returns the value of attribute orig.
-
#times_answered ⇒ Object
Returns the value of attribute times_answered.
-
#times_asked ⇒ Object
Returns the value of attribute times_asked.
-
#trans ⇒ Object
readonly
Returns the value of attribute trans.
-
#variants_number ⇒ Object
readonly
Returns the value of attribute variants_number.
Instance Method Summary collapse
- #asked(answers) ⇒ Object
- #favour ⇒ Object
- #frequency ⇒ Object
-
#initialize(orig, trans, limit) ⇒ Word
constructor
A new instance of Word.
- #learn! ⇒ Object
- #learnt? ⇒ Boolean
Constructor Details
#initialize(orig, trans, limit) ⇒ Word
Returns a new instance of Word.
14 15 16 17 18 19 20 21 |
# File 'lib/learn_words.rb', line 14 def initialize(orig, trans, limit) @orig = orig @trans = trans.split "/" @variants_number = @trans.length @times_asked = 0 @times_answered = 0 @limit = limit end |
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit.
12 13 14 |
# File 'lib/learn_words.rb', line 12 def limit @limit end |
#orig ⇒ Object (readonly)
Returns the value of attribute orig.
11 12 13 |
# File 'lib/learn_words.rb', line 11 def orig @orig end |
#times_answered ⇒ Object
Returns the value of attribute times_answered.
12 13 14 |
# File 'lib/learn_words.rb', line 12 def times_answered @times_answered end |
#times_asked ⇒ Object
Returns the value of attribute times_asked.
12 13 14 |
# File 'lib/learn_words.rb', line 12 def times_asked @times_asked end |
#trans ⇒ Object (readonly)
Returns the value of attribute trans.
11 12 13 |
# File 'lib/learn_words.rb', line 11 def trans @trans end |
#variants_number ⇒ Object (readonly)
Returns the value of attribute variants_number.
11 12 13 |
# File 'lib/learn_words.rb', line 11 def variants_number @variants_number end |
Instance Method Details
#asked(answers) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/learn_words.rb', line 31 def asked(answers) @times_asked += 1 if answers.map( &:downcase ).sort == trans.map( &:downcase ).sort @times_answered += 1 true else false end end |
#favour ⇒ Object
41 42 43 |
# File 'lib/learn_words.rb', line 41 def favour 3*frequency + @times_asked end |
#frequency ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/learn_words.rb', line 23 def frequency if @times_asked == 0 learnt? ? 1.0 : 0.0 else @times_answered.to_f / @times_asked.to_f end end |
#learn! ⇒ Object
49 50 51 |
# File 'lib/learn_words.rb', line 49 def learn! @limit = @times_answered end |
#learnt? ⇒ Boolean
45 46 47 |
# File 'lib/learn_words.rb', line 45 def learnt? @times_answered >= @limit end |