Sha256: 3f5b9c3125749fb74f95759ef7c3293463b79c1b420315d314f29b7ffae7bfdc
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
class MaterialCodeGenerator attr_accessor :material_object, :material_repository delegate :material_class_id_changed?, :material_class_id?, :material_class, to: :material_object def initialize(material_object, material_repository = Material) self.material_object = material_object self.material_repository = material_repository end def generate! return unless materials_code_can_changed? material_object.code = material_code end protected def material_code [material_class.masked_number, next_code].join('.') end def next_code code = previous_material_code end def previous_material_code return 1 if previous_material.blank? previous_material.code.gsub("#{material_class.masked_number}.", '').to_i + 1 end def previous_material @previous_material ||= material_repository .by_material_class_id(material_class.id) .reorder(:code) .last end def materials_code_can_changed? material_class_id_changed? && material_class_id? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
unico-training-7.8.0 | app/business/material_code_generator.rb |