Module: Jancode

Defined in:
lib/jancode.rb,
lib/jancode/gtin.rb,
lib/jancode/gtin8.rb,
lib/jancode/gtin13.rb,
lib/jancode/version.rb

Defined Under Namespace

Classes: GTIN, GTIN13, GTIN8

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.create(code) ⇒ Object

without check digit



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jancode.rb', line 9

def create(code)
  case code.size
  when 12
    company_prefix = code[0..8]
    item_code = code[9..11]
    Jancode::GTIN13.new(company_prefix, item_code)
  when 7
    company_prefix = code[0..5]
    item_code = code[6]
    Jancode::GTIN8.new(company_prefix, item_code)
  else
    raise "Is not 12 or 7 characters"
  end
end

.verification?(code) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jancode.rb', line 24

def verification?(code)
  case code.size
  when 13
    company_prefix = code[0..8]
    item_code = code[9..11]
    jancode = Jancode::GTIN13.new(company_prefix, item_code)
  when 8
    company_prefix = code[0..5]
    item_code = code[6]
    jancode = Jancode::GTIN8.new(company_prefix, item_code)
  else
    raise "Is not 13 or 8 characters"
  end

  jancode.create == code
end