Class: Emporium::Code
- Inherits:
-
Object
- Object
- Emporium::Code
- Defined in:
- lib/emporium/code.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(value) ⇒ Code
constructor
A new instance of Code.
- #valid? ⇒ Boolean
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
#value ⇒ Object
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
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 |