Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 14 |
# File 'lib/parser.rb', line 8 def initialize self. = { length: 12, numbers_only: false, include_special_chars: true } end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/parser.rb', line 6 def @options end |
Instance Method Details
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/parser.rb', line 16 def parse OptionParser.new do |parser| parser.on('-l LENGTH', '--length LENGTH', 'Password length as integer. Default: 12. Ex pgen -l 32', Integer) parser.on('-p [PIN]', '--pin [PIN]', 'Should use a pin password (numbers only). Default: false. Ex: pgen -p | pgen -p true | pgen -p false') do |pin| [:numbers_only] = parse_optional_bool_flag pin end parser.on('-s [SPECIAL]', '--special [SPECIAL]', 'Should use special characters (!?;). Default: true. Ex: pgen -p | pgen -p true | pgen -p false') do |special| [:include_special_chars] = parse_optional_bool_flag special end end.parse!(into: ) end |