Class: Qe::Page

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/qe/page.rb

Instance Method Summary collapse

Instance Method Details

#all_elementsObject

Include nested elements



49
50
51
# File 'app/models/qe/page.rb', line 49

def all_elements
  (elements + elements.collect(&:all_elements)).flatten
end

#complete?(answer_sheet) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/qe/page.rb', line 66

def complete?(answer_sheet)
  all_elements.all? {|e| !e.required?(answer_sheet) || e.has_response?(answer_sheet)}
end

#copy_to(question_sheet) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/qe/page.rb', line 53

def copy_to(question_sheet)
  new_page = Page.new(self.attributes)
  new_page.question_sheet_id = question_sheet.id
  new_page.save(:validate => false)
  self.elements.each do |element|
    if !question_sheet.archived? && element.reuseable?
      PageElement.create(:element => element, :page => new_page)
    else
      element.duplicate(new_page)
    end
  end
end

#has_questions?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/qe/page.rb', line 74

def has_questions?
  all_elements.any? {|e| e.is_a?(Question)}
end

#questions_before_position(position) ⇒ Object

a page is disabled if there is a condition, and that condition evaluates to false could set multiple conditions to influence this question, in which case all must be met def active?

# find first condition that doesn't pass (nil if all pass)
self.conditions.detect { |c| !c.evaluate? }.nil?  # true if all pass

end

def question?

false

end



44
45
46
# File 'app/models/qe/page.rb', line 44

def questions_before_position(position)
  self.elements.where(["#{PageElement.table_name}.position < ?", position])
end

#started?(answer_sheet) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/models/qe/page.rb', line 70

def started?(answer_sheet)
  all_elements.any? {|e| e.has_response?(answer_sheet)}
end