Class: Jancode::GTIN

Inherits:
Object
  • Object
show all
Defined in:
lib/jancode/gtin.rb

Direct Known Subclasses

GTIN13, GTIN8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(company_prefix = nil, item_code = nil) ⇒ GTIN

Returns a new instance of GTIN.



5
6
7
8
# File 'lib/jancode/gtin.rb', line 5

def initialize(company_prefix = nil, item_code = nil)
  @company_prefix = company_prefix
  @item_code = item_code
end

Instance Attribute Details

#company_prefixObject

Returns the value of attribute company_prefix.



3
4
5
# File 'lib/jancode/gtin.rb', line 3

def company_prefix
  @company_prefix
end

#item_codeObject

Returns the value of attribute item_code.



3
4
5
# File 'lib/jancode/gtin.rb', line 3

def item_code
  @item_code
end

Instance Method Details

#check_digitObject



10
11
12
13
14
# File 'lib/jancode/gtin.rb', line 10

def check_digit
  validation
  val = ((sum_numbers(:even) * 3) + sum_numbers(:odd)).to_s[-1].to_i
  val == 0 ? 0 : 10 - val
end

#createObject



16
17
18
# File 'lib/jancode/gtin.rb', line 16

def create
  [@company_prefix, @item_code, check_digit].join
end