Sha256: 9e3b281e5313685acdbd0611d30ac220772abf30a1955cafa5e6a5dbe61c0e08
Contents?: true
Size: 781 Bytes
Versions: 1
Compression:
Stored size: 781 Bytes
Contents
module Faker module Russian module Okpo def okpo(options = {}) if (options.keys - [:sequence_number]).any? raise 'wrong options. just :sequence_number' end sequence = find_sequence(options[:sequence_number]) okpo_digits = okpo_region_numbers(sequence) okpo_digits + okpo_calc(okpo_digits) end private def okpo_region_numbers(sequence) if [true, false][sequence.rand(2)] sprintf '%07d', sequence.rand(10_000_000) else sprintf '%09d', sequence.rand(1_000_000_000) end end def okpo_calc(okpo_digits) (okpo_digits.split(//).map(&:to_i).each_with_index.inject(0) { |s, (p, i)| s + p * (i + 1) } % 11 % 10).to_s end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
faker-russian-0.0.3 | lib/faker/russian/okpo.rb |