Class: Jobshop::Inspection::DeviationCriterion
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Jobshop::Inspection::DeviationCriterion
- Defined in:
- app/models/jobshop/inspection/deviation_criterion.rb
Instance Method Summary collapse
- #criterion_with_build ⇒ Object (also: #criterion)
- #lower ⇒ Object
- #lower=(value) ⇒ Object
- #lower_less_than_upper ⇒ Object
- #mean ⇒ Object
- #nominal ⇒ Object
- #pass?(value) ⇒ Boolean
-
#random ⇒ Object
Generate a random value that has a 90% chance of being in spec.
- #specification ⇒ Object
- #symmetric? ⇒ Boolean
- #upper ⇒ Object
- #upper=(value) ⇒ Object
Instance Method Details
#criterion_with_build ⇒ Object Also known as: criterion
16 17 18 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 16 def criterion_with_build criterion_without_build || build_criterion end |
#lower ⇒ Object
36 37 38 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 36 def lower self[:lower] && Unitwise(self[:lower].truncate(4), self[:unit]) end |
#lower=(value) ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 40 def lower=(value) self[:lower] = if value.respond_to?(:unit) value.convert_to(self[:unit]).value else value end end |
#lower_less_than_upper ⇒ Object
60 61 62 63 64 65 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 60 def lower_less_than_upper return unless lower && upper if lower > upper errors[:base] << "minimum must be less than maximum" end end |
#mean ⇒ Object
28 29 30 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 28 def mean ((nominal + lower) + (nominal + upper)) / 2 end |
#nominal ⇒ Object
32 33 34 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 32 def nominal self[:nominal] && Unitwise(self[:nominal].truncate(4), self[:unit]) end |
#pass?(value) ⇒ Boolean
79 80 81 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 79 def pass?(value) !undersize?(value) && !oversize?(value) end |
#random ⇒ Object
Generate a random value that has a 90% chance of being in spec. TODO: This needs to go in the tests somewhere, not really in the model.
85 86 87 88 89 90 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 85 def random rand_lower = nominal.to_f + lower.to_f * 1.1 rand_upper = nominal.to_f + upper.to_f * 1.1 value = rand(rand_lower..rand_upper) Unitwise(value.truncate(4), self[:unit]) end |
#specification ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 67 def specification @specfication ||= if symmetric? "#{nominal}±#{abs(upper)}" else "#{nominal}\n#{lower}/#{upper}" end end |
#symmetric? ⇒ Boolean
75 76 77 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 75 def symmetric? @symmetrical ||= lower == upper * -1 end |
#upper ⇒ Object
48 49 50 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 48 def upper self[:upper] && Unitwise(self[:upper].truncate(4), self[:unit]) end |
#upper=(value) ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/jobshop/inspection/deviation_criterion.rb', line 52 def upper=(value) self[:upper] = if value.respond_to?(:unit) value.convert_to(self[:unit]).value else value end end |