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

Returns:

  • (boolean)


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

def instore_code?
  @body.start_with?('2')
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