class Ragol::Option
Attributes
default[RW]
description[RW]
matchers[R]
name[RW]
negates[RW]
regexps[RW]
Public Class Methods
new(options = Hash.new, &blk)
click to toggle source
# File lib/ragol/option.rb, line 22 def initialize options = Hash.new, &blk @tags = nil @negates = nil @regexps = nil @name = nil @default = nil @unsets = nil @process = nil @takesvalue = nil @rcnames = nil @description = nil if blk blk.call self end tagsmatch = to_matcher(@tags || options[:tags]) negatesmatch = to_matcher(@negates || options[:negates]) regexpsmatch = to_matcher(@regexps || options[:regexps]) @matchers = Ragol::Matchers.new tagsmatch, negatesmatch, regexpsmatch @name ||= options[:name] || @matchers.name @default ||= options[:default] @unsets ||= options[:unsets] @process ||= options[:process] @takesvalue ||= options[:takesvalue] @rcnames ||= [ options[:rcnames] ].flatten @description ||= options[:description] end
Public Instance Methods
argument_missing()
click to toggle source
# File lib/ragol/option.rb, line 104 def argument_missing if takes_value? == true raise "value expected for option: #{self}" end end
convert(md)
click to toggle source
# File lib/ragol/option.rb, line 84 def convert md md.kind_of?(MatchData) ? md[-1] : md end
do_match(val)
click to toggle source
# File lib/ragol/option.rb, line 88 def do_match val if valuere = value_regexp unless md = valuere.match(val) raise "invalid argument '#{val}' for option: #{self}" end md else val end end
match_next_value(results)
click to toggle source
# File lib/ragol/option.rb, line 128 def match_next_value results if takes_value? == true match_next_value_required results else match_next_value_optional results end end
match_next_value_optional(results)
click to toggle source
# File lib/ragol/option.rb, line 115 def match_next_value_optional results return unless val = results.current_arg return true if val[0] == '-' return results.shift_arg unless valuere = value_regexp if md = valuere.match(results.current_arg) results.shift_arg md else true end end
match_next_value_required(results)
click to toggle source
# File lib/ragol/option.rb, line 110 def match_next_value_required results val = results.shift_arg val && do_match(val) end
match_rc?(field)
click to toggle source
# File lib/ragol/option.rb, line 54 def match_rc? field @rcnames.include?(field) end
post_process(option_set, results, unprocessed)
click to toggle source
# File lib/ragol/option.rb, line 66 def post_process option_set, results, unprocessed resolve_value option_set, results, unprocessed if @unsets option_set.unset results, @unsets end end
resolve_value(option_set, results, unprocessed)
click to toggle source
# File lib/ragol/option.rb, line 74 def resolve_value option_set, results, unprocessed end
set_option_value(md, arg, results)
click to toggle source
# File lib/ragol/option.rb, line 154 def set_option_value md, arg, results value = md == true ? true : convert(md) if @process setargs = [ value, arg, results.unprocessed ][0 ... @process.arity] @process.call(*setargs) end results.set_value name, value end
set_value_for_tag(results, arg)
click to toggle source
# File lib/ragol/option.rb, line 136 def set_value_for_tag results, arg md = if takes_value? take_eq_value(arg) || match_next_value(results) || argument_missing else true end set_option_value md, arg, results end
set_value_negative(results, arg)
click to toggle source
# File lib/ragol/option.rb, line 145 def set_value_negative results, arg set_option_value false, arg, results end
set_value_regexp(results, arg)
click to toggle source
# File lib/ragol/option.rb, line 149 def set_value_regexp results, arg md = @matchers.regexp_match? arg set_option_value md, arg, results end
take_eq_value(opt)
click to toggle source
# File lib/ragol/option.rb, line 99 def take_eq_value opt val = opt.split('=', 2)[1] val && do_match(val) end
takes_value?()
click to toggle source
# File lib/ragol/option.rb, line 62 def takes_value? @takesvalue end
to_doc(io)
click to toggle source
# File lib/ragol/option.rb, line 163 def to_doc io doc = Ragol::Doc.new self doc.to_doc io end
to_matcher(elements)
click to toggle source
# File lib/ragol/option.rb, line 58 def to_matcher elements elements && Ragol::Matcher.new(elements) end
to_s()
click to toggle source
# File lib/ragol/option.rb, line 77 def to_s @matchers.to_s end
value_regexp()
click to toggle source
# File lib/ragol/option.rb, line 81 def value_regexp end