Class: Word

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

Overview

READING WORDS FILE

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#limitObject

Returns the value of attribute limit.



12
13
14
# File 'lib/learn_words.rb', line 12

def limit
  @limit
end

#origObject (readonly)

Returns the value of attribute orig.



11
12
13
# File 'lib/learn_words.rb', line 11

def orig
  @orig
end

#times_answeredObject

Returns the value of attribute times_answered.



12
13
14
# File 'lib/learn_words.rb', line 12

def times_answered
  @times_answered
end

#times_askedObject

Returns the value of attribute times_asked.



12
13
14
# File 'lib/learn_words.rb', line 12

def times_asked
  @times_asked
end

#transObject (readonly)

Returns the value of attribute trans.



11
12
13
# File 'lib/learn_words.rb', line 11

def trans
  @trans
end

#variants_numberObject (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

#favourObject



41
42
43
# File 'lib/learn_words.rb', line 41

def favour
  3*frequency + @times_asked
end

#frequencyObject



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

Returns:

  • (Boolean)


45
46
47
# File 'lib/learn_words.rb', line 45

def learnt?
  @times_answered >= @limit
end