Class: PassForge::Batch
- Inherits:
-
Object
- Object
- PassForge::Batch
- Defined in:
- lib/passforge/batch.rb
Overview
Batch password generator Generate multiple passwords at once
Class Method Summary collapse
-
.generate(count, type = :random, **options) ⇒ Array<String>
Generate multiple passwords.
-
.to_csv(passwords) ⇒ String
Export passwords to CSV format.
-
.to_json(passwords) ⇒ String
Export passwords to JSON format.
Class Method Details
.generate(count, type = :random, **options) ⇒ Array<String>
Generate multiple passwords
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 |
# File 'lib/passforge/batch.rb', line 18 def self.generate(count, type = :random, **) raise ArgumentError, "Count must be at least 1" if count < 1 raise ArgumentError, "Count must be at most 1000" if count > 1000 passwords = [] count.times do password = case type when :random length = .delete(:length) || 12 Generator.generate(length, **) when :passphrase Passphrase.generate(**) when :pronounceable Pronounceable.generate(**) when :pattern Pattern.generate([:pattern] || "Cvccvc99!") else raise ArgumentError, "Unknown type: #{type}" end passwords << password end passwords end |
.to_csv(passwords) ⇒ String
Export passwords to CSV format
48 49 50 |
# File 'lib/passforge/batch.rb', line 48 def self.to_csv(passwords) "Password\n" + passwords.join("\n") end |
.to_json(passwords) ⇒ String
Export passwords to JSON format
55 56 57 58 |
# File 'lib/passforge/batch.rb', line 55 def self.to_json(passwords) require "json" { passwords: passwords, count: passwords.length, generated_at: Time.now.iso8601 }.to_json end |