Class: Unidom::ArticleNumber::Ean8Barcode

Inherits:
ApplicationRecord show all
Includes:
Concerns::AsBarcode, Common::Concerns::ModelExtension
Defined in:
app/models/unidom/article_number/ean8_barcode.rb

Overview

EAN-8 Barcode 是8位条形码。en.wikipedia.org/wiki/EAN-8

Constant Summary collapse

RESTRICTED_DISTRIBUTION_GS1_PREFIXES =
(('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze

Instance Method Summary collapse

Instance Method Details

#code=(code) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'app/models/unidom/article_number/ean8_barcode.rb', line 19

def code=(code)
  code = code.to_s
  write_attribute :code, code
  if code.present?
    write_attribute :gs1_prefix,     code[0..2]
    write_attribute :item_reference, code[3..6]
    write_attribute :check_digit,    code[7]
  end
end

#restricted_distribution?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/unidom/article_number/ean8_barcode.rb', line 29

def restricted_distribution?
  self.class::RESTRICTED_DISTRIBUTION_GS1_PREFIXES.include? gs1_prefix
end