Sha256: 204d25d9bb092fae44d21419ef9300b03d319793ee1e80718066baae163dfdcf
Contents?: true
Size: 734 Bytes
Versions: 1
Compression:
Stored size: 734 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 << 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.1 | lib/raph/parser/flag_parser.rb |