Class: Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



8
9
10
11
12
13
14
# File 'lib/parser.rb', line 8

def initialize
  self.options = {
    length: 12,
    numbers_only: false,
    include_special_chars: true
  }
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/parser.rb', line 6

def options
  @options
end

Instance Method Details

#parseObject



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|
      options[: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|
      options[:include_special_chars] = parse_optional_bool_flag special
    end
  end.parse!(into: options)

  options
end