Class: CatEngine::Question

Inherits:
Struct
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion
Defined in:
lib/cat_engine/question.rb

Defined Under Namespace

Classes: XMLMapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = nil) ⇒ Question

Returns a new instance of Question.



9
10
11
# File 'lib/cat_engine/question.rb', line 9

def initialize attributes = nil
  assign_attributes(attributes || {})
end

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



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

def context
  @context
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



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

def id
  @id
end

#promis_idObject

Returns the value of attribute promis_id

Returns:

  • (Object)

    the current value of promis_id



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

def promis_id
  @promis_id
end

#responseObject

Returns the value of attribute response.



23
24
25
# File 'lib/cat_engine/question.rb', line 23

def response
  @response
end

#response_beforeObject

Returns the value of attribute response_before

Returns:

  • (Object)

    the current value of response_before



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

def response_before
  @response_before
end

#responsesObject

Returns the value of attribute responses

Returns:

  • (Object)

    the current value of responses



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

def responses
  @responses
end

#responses_attributesObject

Returns the value of attribute responses_attributes.



23
24
25
# File 'lib/cat_engine/question.rb', line 23

def responses_attributes
  @responses_attributes
end

#selected_response_indexObject

Returns the value of attribute selected_response_index.



23
24
25
# File 'lib/cat_engine/question.rb', line 23

def selected_response_index
  @selected_response_index
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



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

def title
  @title
end

Instance Method Details

#context_and_titleObject



13
14
15
# File 'lib/cat_engine/question.rb', line 13

def context_and_title
  [context, title].select(&:present?).join(" ")
end

#persisted?Boolean

Returns:

  • (Boolean)


21
# File 'lib/cat_engine/question.rb', line 21

def persisted?; false; end

#selected_responseObject



25
26
27
28
29
30
31
# File 'lib/cat_engine/question.rb', line 25

def selected_response
  if selected_response_index
    responses_attributes[selected_response_index]
  else
    { id: "00000000-0000-0000-0000-000000000000", title: response || "Skipped" }
  end
end

#xml=(xml) ⇒ Object



17
18
19
# File 'lib/cat_engine/question.rb', line 17

def xml= xml
  assign_attributes XMLMapper.new(xml).to_h
end