Sha256: b5dc5e5e12387f8d02e11362a3b2a7402710f99de880d7009bee84bf726d419b

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literals: true

module Jobshop
  class Inspection::Report < ApplicationRecord
    self.primary_keys = %i[ organization_id report_id ]

    after_initialize { self.report_id ||= SecureRandom.uuid if new_record? }

    belongs_to :organization, inverse_of: :inspection_reports

    has_many :criteria, -> { includes(:criterion).order(:position) },
      foreign_key: %i[ organization_id report_id ], inverse_of: :report

    has_many :limit_criteria, inverse_of: :report,
      foreign_key: %i[ organization_id report_id ]

    has_many :tuples, -> { order(:position) },  inverse_of: :report,
      foreign_key: %i[ organization_id report_id ]

    def ascii
      require "terminal-table"
      table = Terminal::Table.new do |t|
        t.title = "Inspection Report"
        t << [ "Feature" ].concat(criteria.map(&:criterion).map(&:name))
        t << [ "Specification" ].concat(criteria.map(&:criterion).map(&:specification))
        tuples.each do |tuple|
          results = criteria.map do |criterion|
            tuple.results.find_by(criterion: criterion)
          end
          t << [ tuple.position ].concat(results.map(&:value))
        end
      end

      puts table
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jobshop-0.0.163 app/models/jobshop/inspection/report.rb