Class: Jancode::GTIN
- Inherits:
-
Object
- Object
- Jancode::GTIN
- Defined in:
- lib/jancode/gtin.rb
Instance Attribute Summary collapse
-
#company_prefix ⇒ Object
Returns the value of attribute company_prefix.
-
#item_code ⇒ Object
Returns the value of attribute item_code.
Instance Method Summary collapse
- #check_digit ⇒ Object
- #create ⇒ Object
-
#initialize(company_prefix = nil, item_code = nil) ⇒ GTIN
constructor
A new instance of GTIN.
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_prefix ⇒ Object
Returns the value of attribute company_prefix.
3 4 5 |
# File 'lib/jancode/gtin.rb', line 3 def company_prefix @company_prefix end |
#item_code ⇒ Object
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_digit ⇒ Object
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 |
#create ⇒ Object
16 17 18 |
# File 'lib/jancode/gtin.rb', line 16 def create [@company_prefix, @item_code, check_digit].join end |