Sha256: 001eb94142c5b147bb1a4e05bf884277c5b457e66107317fdb236b11fe7c83f9

Contents?: true

Size: 910 Bytes

Versions: 14

Compression:

Stored size: 910 Bytes

Contents

# QuestionGrid
# - Represents a grid layout of a set of questions, with a total at the bottom
#
# :kind         - 'QuestionGridWithTotal' for single table inheritance (STI)
# :content      - questions
# :total_cols    - Which column(s) of the grid should be used for totals

module Fe
  class QuestionGridWithTotal < QuestionGrid
    def totals(app)
      totals = []
      col = 0
      row = []
      elements.each do |el|
        value = el.display_response(app) if el.respond_to?(:display_response) && el.display_response(app).present?

        if value && value.present? # keep totals nil until there actually is a value, so that we can only display a total only if at least one row had a value
          value = value.tr("^0-9.", '').to_f
          totals[col] = (totals[col].present? ? totals[col] + value : value)
        end
        col = (col + 1) % num_cols
      end
      totals
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fe-2.1.5 app/models/fe/question_grid_with_total.rb
fe-2.1.4 app/models/fe/question_grid_with_total.rb
fe-2.1.3 app/models/fe/question_grid_with_total.rb
fe-2.1.2 app/models/fe/question_grid_with_total.rb
fe-2.1.1 app/models/fe/question_grid_with_total.rb
fe-2.0.8 app/models/fe/question_grid_with_total.rb
fe-2.0.6 app/models/fe/question_grid_with_total.rb
fe-2.0.5 app/models/fe/question_grid_with_total.rb
fe-2.0.4 app/models/fe/question_grid_with_total.rb
fe-2.0.3 app/models/fe/question_grid_with_total.rb
fe-2.0.2 app/models/fe/question_grid_with_total.rb
fe-2.0.1 app/models/fe/question_grid_with_total.rb
fe-2.0.0 app/models/fe/question_grid_with_total.rb
fe-1.0.0 app/models/fe/question_grid_with_total.rb