Sha256: 917b6e60217738f136ea6b792d108127d2985692feb709b4ed9efa23276c595b

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literals: true

module Jobshop
  class Inspection::Result < ApplicationRecord
    FALSE_VALUES = [false, 0, "0", "f", "F", "false", "FALSE", "off", "OFF"]

    self.primary_keys = %i[ organization_id report_id criterion_id criterion_type position ]

    belongs_to :organization

    belongs_to :report, class_name: "Jobshop::Inspection::Report",
      foreign_key: %i[ organization_id report_id ]

    belongs_to :criterion, polymorphic: true, optional: true, dependent: :destroy,
      foreign_key: %i[ organization_id report_id criterion_id criterion_type ]

    belongs_to :tuple, class_name: "Jobshop::Inspection::Tuple",
      foreign_key: %i[ organization_id report_id position ]

    def value
      if self[:unit] == "boolean"
        !!self[:value]
      else
        self[:value] && Unitwise(self[:value].truncate(4), self[:unit])
      end
    end

    def value=(value)
      if criterion.unit == "boolean"
        self[:value] = value
        self[:unit] = "boolean"
      else
        if value.respond_to?(:unit)
          self[:value] = value.value
          self[:unit] = value.unit
        else
          self[:value] = value
        end
      end
    end

    def in_spec?
      criterion.pass?(self[:value])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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