Class: ODDB::MedData::EanFactory
- Defined in:
- ext/meddata/src/ean_factory.rb
Instance Method Summary collapse
- #clarify ⇒ Object
-
#initialize(start, max = 13) ⇒ EanFactory
constructor
A new instance of EanFactory.
- #next ⇒ Object
Constructor Details
#initialize(start, max = 13) ⇒ EanFactory
Returns a new instance of EanFactory.
9 10 11 12 |
# File 'ext/meddata/src/ean_factory.rb', line 9 def initialize(start, max=13) @current = (start.to_i - 1).to_s @max = max - 1 end |
Instance Method Details
#clarify ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'ext/meddata/src/ean_factory.rb', line 19 def clarify if(@current.size < @max) @current << '0' elsif(@current.size == @max) @current << Ean13.checksum(@current) else @current = @current[0,@max] self.next end end |
#next ⇒ Object
13 14 15 16 17 18 |
# File 'ext/meddata/src/ean_factory.rb', line 13 def next if(@current[-1] == ?9) @current.chop! end @current.next! end |