Module: Inspectable

Extended by:
ActiveSupport::Concern
Included in:
InspectionCalibration, InspectionPoint
Defined in:
app/models/concerns/inspectable.rb

Instance Method Summary collapse

Instance Method Details

#extremum_size(type) ⇒ Object

Primitives


43
44
45
46
47
# File 'app/models/concerns/inspectable.rb', line 43

def extremum_size(type)
  raise 'Type must either be `min` or `max`' unless %w[min max].include?(type.to_s)
  value = send(:"#{type}imal_size_value")
  (value || 0).in(grading_sizes_unit)
end

#projected_total(dimension) ⇒ Object


30
31
32
33
# File 'app/models/concerns/inspectable.rb', line 30

def projected_total(dimension)
  number_of_samples = (total_area / sample_area)
  (quantity_in_unit(dimension) * number_of_samples)
end

#quantity_in_unit(dimension) ⇒ Object


49
50
51
# File 'app/models/concerns/inspectable.rb', line 49

def quantity_in_unit(dimension)
  quantity_value(dimension).in(quantity_unit(dimension))
end

#quantity_value(dimension) ⇒ Object

Quantities


56
57
58
59
# File 'app/models/concerns/inspectable.rb', line 56

def quantity_value(dimension)
  return (send(:"#{dimension}_value") || 0) if respond_to?(:"#{dimension}_value")
  unknown_dimension(dimension)
end

#quantity_yield(dimension) ⇒ Object


35
36
37
38
39
# File 'app/models/concerns/inspectable.rb', line 35

def quantity_yield(dimension)
  quantity = quantity_in_unit(dimension).to_d(quantity_unit(dimension))
  y = (quantity / sample_area).in(default_per_area_unit(dimension))
  y.in(quantity_per_area_unit(dimension))
end