Class: Raph::Parser::FlagParser

Inherits:
BaseParser show all
Defined in:
lib/raph/parser/flag_parser.rb

Overview

Considers option as flag if and only if it's name starts with one dash and follows by one word character or starts with two dashes and follows by 2 or more word chacters or dashes.

Assumes that each option doesn't have spaces.

Example of flags: '-h' '-T' '--config'

Example of non-flags: 'option' '---option2' '--h'

Instance Method Summary collapse

Methods inherited from BaseParser

#id

Instance Method Details

#flag?(option) ⇒ Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/raph/parser/flag_parser.rb', line 26

def flag?(option)
  !!(option =~ /^-[\w]$/ || option =~ /^--[\w][\w-]+$/)
end

#parse(args) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/raph/parser/flag_parser.rb', line 18

def parse(args)
  flags = []
  args.each do |a|
    flags << to_underscored_sym(a) if flag? a
  end
  flags
end