Module: Generators
- Defined in:
- lib/cuculungwa/generators.rb
Instance Method Summary collapse
- #get_random_currency_symbol ⇒ Object
- #get_unique_email(prefix = 'email', domain = 'test.com') ⇒ Object
- #nip_generator(data_type) ⇒ Object
-
#pesel_generator(data_type, adult = true) ⇒ Object
generators below perform typical polish data.
- #pl_iban_generator(data_type = 'positive_set', bank_prefix = nil, polish_format = false) ⇒ Object
Instance Method Details
#get_random_currency_symbol ⇒ Object
7 8 9 10 11 |
# File 'lib/cuculungwa/generators.rb', line 7 def get_random_currency_symbol currencies = %w( PLN EUR USD GBP CZK) currencies.sample end |
#get_unique_email(prefix = 'email', domain = 'test.com') ⇒ Object
2 3 4 5 |
# File 'lib/cuculungwa/generators.rb', line 2 def get_unique_email(prefix = 'email', domain = 'test.com') # returns unique test email "#{prefix}-#{(Time.now.to_f * 1_000_000).to_i}@#{domain}" end |
#nip_generator(data_type) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cuculungwa/generators.rb', line 48 def nip_generator(data_type) # returns polish business registration number if data_type.eql? 'positive_data_set' weights = [6, 5, 7, 2, 3, 4, 5, 6, 7] code = rand(998 - 101) + 101 number = rand(1_000_000) nip = code.to_s + number.to_s.rjust(6, '0') c = nip.split(//).map!(&:to_i) sum = c.zip(weights).map! { |x| x[0] * x[1] }.reduce(:+) % 11 sum = sum == 10 ? 0 : sum return nip + sum.to_s elsif data_type.eql? 'negative_data_set' return '000' else return '' end end |
#pesel_generator(data_type, adult = true) ⇒ Object
generators below perform typical polish data
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cuculungwa/generators.rb', line 15 def pesel_generator(data_type, adult = true) # returns polish registration number of the population if data_type.eql? 'positive_data_set' weights = Array[1, 3, 7, 9, 1, 3, 7, 9, 1, 3] current_year = Time.new.year temp_up = (current_year - 18).to_s[-2..-1].to_i temp_down = (current_year - 99).to_s[-2..-1].to_i if adult == true year = (rand * 100).to_i year = (rand * 100).to_i until (temp_down < year) && (year < temp_up) else year = (rand * 100).to_i year = (rand * 100).to_i until (temp_down > year) || (year > temp_up) end month = rand * 12 + 1 day = rand * 28 + 1 evidence_number = rand * 999 sex = rand * 9 pesel = '%02d%02d%02d%03d%d' % [year, month, day, evidence_number, sex] temp_cs = 0 pesel_elem = pesel.each_char.map(&:to_i) for i in 0..weights.length - 1 temp_cs += weights[i] * pesel_elem[i] end control_sum = (10 - (temp_cs % 10)) % 10 return pesel + control_sum.to_s elsif data_type.eql? 'negative_data_set' return '00000000000' else return '' end end |
#pl_iban_generator(data_type = 'positive_set', bank_prefix = nil, polish_format = false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/cuculungwa/generators.rb', line 68 def pl_iban_generator(data_type = 'positive_set', bank_prefix = nil, polish_format = false) # return polish fashioned iban bank account number # data_type: if you want correct iban use positive_set, anything else will return 00111122223333444455556666 # bank_prefix: if you want specify bank prefix (minimum 4 and maximum 8 digits) # polish_format: if you want add spaces for readability bank_prefix ||= sprintf('%08d', rand(10**8)) bank_prefix = bank_prefix.to_s.gsub(/\s+/, '') raise 'Bank prefix error!' if bank_prefix.length < 4 bank_prefix << '0001' if bank_prefix.length == 4 if data_type.eql? 'positive_set' account_no = sprintf('%016d', rand(10**16)) num = bank_prefix + account_no + '252100' control_digit = sprintf('%02d', 98 - (num.to_i % 97)) number = control_digit + bank_prefix + account_no else number = '00111122223333444455556666' end if polish_format pl_iban_formatter(number) else number end end |