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)


72
73
74
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 72

def bound?
  !unbound?
end

#criterionObject



17
18
19
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 17

def criterion
  super || build_criterion
end

#maximumObject



39
40
41
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 39

def maximum
  self[:maximum] && Unitwise(self[:maximum].truncate(4), self[:unit])
end

#maximum=(value) ⇒ Object



43
44
45
46
47
48
49
50
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 43

def maximum=(value)
  if value && value.respond_to?(:unit)
    self[:maximum] = value.value
    self[:unit] = value.unit
  else
    self[:maximum] = value
  end
end

#minimumObject



26
27
28
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 26

def minimum
  self[:minimum] && Unitwise(self[:minimum].truncate(4), self[:unit])
end

#minimum=(value) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 30

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)


76
77
78
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 76

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

#qualifierObject



58
59
60
61
62
63
64
65
66
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 58

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.



92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 92

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



52
53
54
55
56
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 52

def specification
  @specification ||= [
    qualifier, [ minimum, maximum ].compact.join("/")
  ].compact.join("\n")
end

#unbound?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/jobshop/inspection/limit_criterion.rb', line 68

def unbound?
  !minimum ^ !maximum
end