Class: ODDB::Ean13

Inherits:
String show all
Defined in:
src/model/ean13.rb,
ext/export/src/oddb_yaml.rb

Constant Summary

Constants included from Util::IsoLatin1

DOWNCASE_PAIRS, DOWNCASE_PTRN

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from String

#downcase, #downcase!, #src

Methods included from LevenshteinDistance

#ld, #ld_min

Methods included from Util::IsoLatin1

#locale_downcase!

Constructor Details

- (Ean13) initialize(str)

A new instance of Ean13



8
9
10
11
12
13
# File 'src/model/ean13.rb', line 8

def initialize(str)
  super(str.strip)
  unless(valid?)
    raise SBSM::InvalidDataError.new(:e_invalid_ean_code, :ean13, str)
  end
end

Class Method Details

+ (Object) checksum(str)



14
15
16
17
18
19
20
21
22
23
# File 'src/model/ean13.rb', line 14

def Ean13.checksum(str)
  str = str.strip
  sum = 0 
  val =  str.split(//u)
  12.times { |idx|
    fct = ((idx%2)*2)+1
    sum += fct*val[idx].to_i
  }
  ((10-(sum%10))%10).to_s
end

+ (Object) new_unchecked(str)



24
25
26
# File 'src/model/ean13.rb', line 24

def Ean13.new_unchecked(str)
  self.new(str.strip.ljust(12, '0')+checksum(str))
end

+ (Boolean) yaml_tag_subclasses?

Returns:

  • (Boolean)


233
234
235
# File 'ext/export/src/oddb_yaml.rb', line 233

def self.yaml_tag_subclasses?
  false
end