Class: CatEngine::Bank

Inherits:
Struct
  • Object
show all
Defined in:
lib/cat_engine/bank.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#full_historyObject

Returns the value of attribute full_history

Returns:

  • (Object)

    the current value of full_history



5
6
7
# File 'lib/cat_engine/bank.rb', line 5

def full_history
  @full_history
end

#historyObject

Returns the value of attribute history

Returns:

  • (Object)

    the current value of history



5
6
7
# File 'lib/cat_engine/bank.rb', line 5

def history
  @history
end

#idObject Also known as: to_param

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/cat_engine/bank.rb', line 5

def id
  @id
end

Instance Method Details

#current_questionObject



14
15
16
# File 'lib/cat_engine/bank.rb', line 14

def current_question
  Question.new(xml: xml) unless finished?
end

#finished?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cat_engine/bank.rb', line 22

def finished?
  xml.root.name == "Results"
end

#nameObject



10
11
12
# File 'lib/cat_engine/bank.rb', line 10

def name
  xml.root["Name"]
end

#paired?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/cat_engine/bank.rb', line 6

def paired?
  id.include? "Illness Impact"
end

#standard_errorObject



31
32
33
34
# File 'lib/cat_engine/bank.rb', line 31

def standard_error
  return unless xml.root.key?("StdError")
  (10 * xml.root["StdError"].to_f).round
end

#thetaObject



26
27
28
29
# File 'lib/cat_engine/bank.rb', line 26

def theta
  return unless xml.root.key?("Theta")
  (10 * xml.root["Theta"].to_f + 50).round
end

#to_hObject



36
37
38
39
40
41
42
# File 'lib/cat_engine/bank.rb', line 36

def to_h
  {
    finished: finished?,
    theta: theta,
    standard_error: standard_error,
  }
end

#valid_answer?(response_id) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cat_engine/bank.rb', line 18

def valid_answer?(response_id)
  engine.valid_history?(id, [history, response_id].join(" "))
end