Class: ODDB::MedData::EanFactory

Inherits:
Object
  • Object
show all
Defined in:
ext/meddata/src/ean_factory.rb

Instance Method Summary (collapse)

Constructor Details

- (EanFactory) initialize(start, max = 13)

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

- (Object) clarify



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

- (Object) next



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