class DockCheck::Ogrn

Public Class Methods

check(document) click to toggle source
# File lib/dockcheck/ogrn.rb, line 7
def self.check(document)
  ogrn = document[:content]

  case ogrn.length
  when 13
    document[:correct] =
      if DockHelper.only_digits?(ogrn)
        ogrn_valid?(ogrn)
      else
        false
      end
  else
    document[:error] = 'Incorrect ogrn numbers count!'
  end

  document
end
name() click to toggle source
# File lib/dockcheck/ogrn.rb, line 25
def self.name
  :ogrn
end

Private Class Methods

ogrn_valid?(ogrn) click to toggle source
# File lib/dockcheck/ogrn.rb, line 31
def self.ogrn_valid?(ogrn)
  first_code = ogrn[0..12].to_i
  second_code = (first_code / 11).floor * 11
  result_sum = (first_code - second_code) % 10
  result_sum == ogrn[13].to_i
end