Sha256: d08345c2d59dcedb619198d0be0dfd35748f5c8f7c64b1187f05606bdfda8ee8
Contents?: true
Size: 785 Bytes
Versions: 1
Compression:
Stored size: 785 Bytes
Contents
require 'raph/parser/base_parser' module Raph module Parser # 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' class FlagParser < BaseParser def parse(args) flags = [] args.each do |a| flags << to_underscored_sym(a) if flag? a end flags end def flag?(option) option =~ /^-[\w]$/ || option =~ /^--[\w][\w-]+$/ end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
raph-0.0.2 | lib/raph/parser/flag_parser.rb |