Module: Quby::AnswersHelper

Defined in:
app/helpers/quby/answers_helper.rb

Instance Method Summary collapse

Instance Method Details

#different_header(item, previous_item) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/quby/answers_helper.rb', line 23

def different_header(item, previous_item)
  return true unless item.score_header == previous_item&.score_header && previous_item.respond_to?(:options)
  case item.score_header
  when :question_description
    return item.description != previous_item.description
  when :value
    return previous_item.options.map(&:value) != item.options.map(&:value)
  when :description
    return previous_item.options.map(&:description) != item.options.map(&:description)
  end
end

#get_item(table, rowi, j) ⇒ Object



40
41
42
# File 'app/helpers/quby/answers_helper.rb', line 40

def get_item(table, rowi, j)
  table.item_table[rowi][j]
end

#get_question(table, rowi, j) ⇒ Object



35
36
37
38
# File 'app/helpers/quby/answers_helper.rb', line 35

def get_question(table, rowi, j)
  q = get_item(table, rowi, j)
  q.is_a?(Quby::Questionnaires::Entities::Question) ? q : nil
end

#get_validation_json(validations) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/quby/answers_helper.rb', line 5

def get_validation_json(validations)
  result = {}
  validations.each_pair do |qkey, valar|
    result[qkey] = valar.map do |val|
      if val[:type] == :regexp
        valc = val.clone
        valc[:matcher] = valc[:matcher].source.to_s
        # Replace single backslashes with two backslashes
        valc[:matcher].gsub!("\\", "\\\\")
        valc
      else
        val
      end
    end
  end
  result.to_json
end

#light_dark_for(cyclei, same_question) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/helpers/quby/answers_helper.rb', line 44

def light_dark_for(cyclei, same_question)
  if same_question
    return ""
  elsif cyclei.modulo(2) == 0
    return "light"
  else
    return "dark"
  end
end