Class: Jobshop::Inspection::LimitCriterion

Inherits:
ApplicationRecord show all
Defined in:
app/models/jobshop/inspection/limit_criterion.rb

Instance Method Summary collapse

Instance Method Details

#bound?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 70

def bound?
  !unbound?
end

#criterionObject



15
16
17
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 15

def criterion
  super || build_criterion
end

#maximumObject



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

#minimumObject



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

Returns:

  • (Boolean)


74
75
76
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 74

def pass?(value)
  !undersize?(value) && !oversize?(value)
end

#qualifierObject



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

#randomObject

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

#specificationObject



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

Returns:

  • (Boolean)


66
67
68
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 66

def unbound?
  !minimum ^ !maximum
end