Class: PasswordAndOrdinals
- Inherits:
-
Object
- Object
- PasswordAndOrdinals
- Defined in:
- lib/password_and_ordinals.rb
Instance Method Summary collapse
- #characters ⇒ Object
-
#initialize(password, ordinals) ⇒ PasswordAndOrdinals
constructor
A new instance of PasswordAndOrdinals.
Constructor Details
#initialize(password, ordinals) ⇒ PasswordAndOrdinals
Returns a new instance of PasswordAndOrdinals.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/password_and_ordinals.rb', line 7 def initialize(password, ordinals) raise(ArgumentError, "#{ordinals} does not ask for any characters") if ordinals.empty? raise(ArgumentError, "#{ordinals} only asks for one character") if ordinals.one? raise(ArgumentError, "#{ordinals} is not in ascending order") unless sorted?(ordinals) raise(ArgumentError, "#{ordinals.uniq.to_sentence} duplicated in #{ordinals}") unless uniq?(ordinals) raise(ArgumentError, "#{ordinals} would reveal entire password") unless ordinals.size < password.size # needs to come after checking duplicates raise(ArgumentError, "#{ordinals_out_of_bounds(password, ordinals).to_sentence} out of bounds") unless ordinals.all? { |i| i.in? ordinal_range(password) } @password_array = password.chars @indices = indices ordinals end |
Instance Method Details
#characters ⇒ Object
22 23 24 |
# File 'lib/password_and_ordinals.rb', line 22 def characters @indices.map { |i| @password_array.at i } end |