Class: PasswordCharacters::PasswordAndOrdinals
- Inherits:
-
Object
- Object
- PasswordCharacters::PasswordAndOrdinals
- Defined in:
- lib/password_characters.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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/password_characters.rb', line 10 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} does not only ask for integers") unless ordinals.all? { |o| o.is_a? Fixnum } 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
27 28 29 |
# File 'lib/password_characters.rb', line 27 def characters @indices.map { |i| @password_array.at i } end |