Class: Fe::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Fe::Page
- Defined in:
- app/models/fe/page.rb
Instance Method Summary collapse
-
#all_elements ⇒ Object
Include nested elements.
- #complete?(answer_sheet) ⇒ Boolean
- #copy_to(question_sheet) ⇒ Object
- #has_questions? ⇒ Boolean
-
#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.
- #started?(answer_sheet) ⇒ Boolean
Instance Method Details
#all_elements ⇒ Object
Include nested elements
60 61 62 |
# File 'app/models/fe/page.rb', line 60 def all_elements (elements + elements.collect(&:all_elements)).flatten end |
#complete?(answer_sheet) ⇒ Boolean
77 78 79 |
# File 'app/models/fe/page.rb', line 77 def complete?(answer_sheet) all_elements.all? {|e| !e.required?(answer_sheet) || e.has_response?(answer_sheet)} end |
#copy_to(question_sheet) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/fe/page.rb', line 64 def copy_to(question_sheet) new_page = Fe::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? Fe::PageElement.create(:element => element, :page => new_page) else element.duplicate(new_page) end end end |
#has_questions? ⇒ Boolean
85 86 87 |
# File 'app/models/fe/page.rb', line 85 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
55 56 57 |
# File 'app/models/fe/page.rb', line 55 def questions_before_position(position) self.elements.where(["#{Fe::PageElement.table_name}.position < ?", position]) end |
#started?(answer_sheet) ⇒ Boolean
81 82 83 |
# File 'app/models/fe/page.rb', line 81 def started?(answer_sheet) all_elements.any? {|e| e.has_response?(answer_sheet)} end |