Class: Jan::Code

Inherits:
String
  • Object
show all
Defined in:
lib/jan/code.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Code

Returns a new instance of Code.

Parameters:

  • code (String)


7
8
9
10
11
# File 'lib/jan/code.rb', line 7

def initialize(code)
  @body = Jan::CodeBody.new(code[0..-2])
  @check_digit = Jan::CheckDigit.new(code[-1])
  super(code)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



13
14
15
# File 'lib/jan/code.rb', line 13

def body
  @body
end

#check_digitObject (readonly)

Returns the value of attribute check_digit.



13
14
15
# File 'lib/jan/code.rb', line 13

def check_digit
  @check_digit
end

Instance Method Details

#instore_code?boolean

Deprecated.

Use ‘instore_marking?` instead.

Returns:

  • (boolean)


22
23
24
# File 'lib/jan/code.rb', line 22

def instore_code?
  instore_marking?
end

#instore_marking?boolean

Returns:

  • (boolean)


27
28
29
# File 'lib/jan/code.rb', line 27

def instore_marking?
  @body.start_with?('2')
end

#source_marking?boolean

Returns:

  • (boolean)


32
33
34
# File 'lib/jan/code.rb', line 32

def source_marking?
  !instore_marking?
end

#valid?boolean

Returns:

  • (boolean)


16
17
18
# File 'lib/jan/code.rb', line 16

def valid?
  @body.valid? && @check_digit.valid? && @body.calculate_check_digit == @check_digit
end