Class: Emporium::Code

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Code

Returns a new instance of Code.



5
6
7
8
# File 'lib/emporium/code.rb', line 5

def initialize(value)
  @value, @check_digit, @code = value, value[-1, 1].to_i, value.chop
  attach_methods!
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/emporium/code.rb', line 3

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/emporium/code.rb', line 10

def valid?
  return unless (@value =~ /^[0-9]+$/) != nil
  compute(@code.odds, @code.evens) == @check_digit
end