class GS1::Barcode::Healthcare

Barcode for boxes in healthcare business.

Public Instance Methods

to_s(level: AIDCMarketingLevels::ENHANCED, separator: GS1.configuration.barcode_separator) click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 8
def to_s(level: AIDCMarketingLevels::ENHANCED, separator: GS1.configuration.barcode_separator)
  return unless valid?(level: level)

  @params_order.each_with_object('') do |param, out|
    record = send(param)

    next unless record.to_ai

    out << record.to_ai
    out << separator if record.class.separator? && param != @params_order.last
  end
end
valid?(level: AIDCMarketingLevels::ENHANCED) click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 21
def valid?(level: AIDCMarketingLevels::ENHANCED)
  return false unless AIDCMarketingLevels::ALL.include?(level)

  validate(level)

  errors.empty?
end

Private Instance Methods

validate(level) click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 31
def validate(level)
  errors.clear

  validate_minimum
  return if level == AIDCMarketingLevels::MINIMUM

  validate_enhanced
  return if level == AIDCMarketingLevels::ENHANCED

  validate_highest
end
validate_attribute(attribute_name) click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 56
def validate_attribute(attribute_name)
  attribute = public_send(attribute_name)

  if attribute.nil?
    errors[attribute_name] << Error.new(:blank)
  elsif !attribute.valid?
    errors[attribute_name] << Error.new(:invalid)
  end
end
validate_enhanced() click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 47
def validate_enhanced
  validate_attribute(:batch)
  validate_attribute(:expiration_date)
end
validate_highest() click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 52
def validate_highest
  validate_attribute(:serial_number)
end
validate_minimum() click to toggle source
# File lib/gs1/barcode/healthcare.rb, line 43
def validate_minimum
  validate_attribute(:gtin)
end