Class: Quby::Questionnaires::Entities::Panel
- Defined in:
- lib/quby/questionnaires/entities/panel.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#key ⇒ Object
Returns the value of attribute key.
-
#questionnaire ⇒ Object
readonly
Returns the value of attribute questionnaire.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from Item
#presentation, #raw_content, #switch_cycle
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #index ⇒ Object
-
#initialize(options = {}) ⇒ Panel
constructor
A new instance of Panel.
- #json_items ⇒ Object
- #next ⇒ Object
- #prev ⇒ Object
- #validations ⇒ Object
Methods inherited from Item
Constructor Details
#initialize(options = {}) ⇒ Panel
Returns a new instance of Panel.
14 15 16 17 18 19 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 14 def initialize( = {}) @questionnaire = [:questionnaire] @title = [:title] @key = [:key] @items = [:items] || [] end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
10 11 12 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 10 def items @items end |
#key ⇒ Object
Returns the value of attribute key.
11 12 13 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 11 def key @key end |
#questionnaire ⇒ Object (readonly)
Returns the value of attribute questionnaire.
12 13 14 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 12 def questionnaire @questionnaire end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 9 def title @title end |
Instance Method Details
#as_json(options = {}) ⇒ Object
21 22 23 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 21 def as_json( = {}) super.merge(title: title, index: index, items: json_items) end |
#index ⇒ Object
25 26 27 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 25 def index @questionnaire.panels.index(self) end |
#json_items ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 49 def json_items items.map do |item| case item when Text { type: 'html', html: item.html } when Question next if item.table # things inside a table are added to the table, AND ALSO to the panel. skip them. { type: 'question', key: item.key } when Table { type: "table" } end end.compact end |
#next ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 29 def next this_panel_index = index if this_panel_index < @questionnaire.panels.size return @questionnaire.panels[this_panel_index + 1] else nil end end |
#prev ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 39 def prev this_panel_index = index if this_panel_index > 0 return @questionnaire.panels[this_panel_index - 1] else nil end end |
#validations ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/quby/questionnaires/entities/panel.rb', line 63 def validations vals = {} items.each do |item| if item.is_a? Question item..each do |opt| if opt.questions opt.questions.each do |q| vals[q.key] = q.validations end end end vals[item.key] = item.validations end end vals end |