Class: PasswordCharacters::OrdinalParser

Inherits:
Object
  • Object
show all
Defined in:
lib/password_characters.rb

Instance Method Summary collapse

Constructor Details

#initialize(string, password = nil) ⇒ OrdinalParser

Returns a new instance of OrdinalParser.



55
56
57
58
# File 'lib/password_characters.rb', line 55

def initialize(string, password=nil)
  @input = string
  @password = password
end

Instance Method Details

#ordinalObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/password_characters.rb', line 60

def ordinal
  case @input
    when /the last/
      @password.length
    when /second (from|to) last/
      @password.length - 1
    when /third from last/
      @password.length - 2
    when /fourth from last/
      @password.length - 3
    when /first/
      1
    when /second/
      2
    when /third/
      3
    when /fourth/
      4
    else
      @input[/\d+/].to_i
  end
end