Class: Jobshop::Inspection::LimitCriterion
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Jobshop::Inspection::LimitCriterion
- Defined in:
- app/models/jobshop/inspection/limit_criterion.rb
Instance Method Summary collapse
- #bound? ⇒ Boolean
- #criterion ⇒ Object
- #maximum ⇒ Object
- #maximum=(value) ⇒ Object
- #minimum ⇒ Object
- #minimum=(value) ⇒ Object
- #pass?(value) ⇒ Boolean
- #qualifier ⇒ Object
-
#random ⇒ Object
Generate a random value that has a 90% chance of being in spec.
- #specification ⇒ Object
- #unbound? ⇒ Boolean
Instance Method Details
#bound? ⇒ Boolean
70 71 72 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 70 def bound? !unbound? end |
#criterion ⇒ Object
15 16 17 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 15 def criterion super || build_criterion end |
#maximum ⇒ Object
37 38 39 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 37 def maximum self[:maximum] && Unitwise(self[:maximum].truncate(4), self[:unit]) end |
#maximum=(value) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 41 def maximum=(value) if value && value.respond_to?(:unit) self[:maximum] = value.value self[:unit] = value.unit else self[:maximum] = value end end |
#minimum ⇒ Object
24 25 26 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 24 def minimum self[:minimum] && Unitwise(self[:minimum].truncate(4), self[:unit]) end |
#minimum=(value) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 28 def minimum=(value) if value && value.respond_to?(:unit) self[:minimum] = value.value self[:unit] = value.unit else self[:minimum] = value end end |
#pass?(value) ⇒ Boolean
74 75 76 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 74 def pass?(value) !undersize?(value) && !oversize?(value) end |
#qualifier ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 56 def qualifier @qualifier ||= if minimum && !maximum "Minimum" elsif maximum && !minimum "Maximum" else nil end 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.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 90 def random value = if bound? rand(self[:minimum].to_f..self[:maximum].to_f) * 1.1 elsif maximum rand(self[:maximum].to_f) * 1.1 elsif minimum rand((self[:minimum].to_f * 0.8)..(self[:minimum].to_f * 2.0)) end Unitwise(value, self[:unit]) end |
#specification ⇒ Object
50 51 52 53 54 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 50 def specification @specification ||= [ qualifier, [ minimum, maximum ].compact.join("/") ].compact.join("\n") end |
#unbound? ⇒ Boolean
66 67 68 |
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 66 def unbound? !minimum ^ !maximum end |