class Toys::Flag::Resolution
The result of looking up a flag by name.
Attributes
The flag string that was looked up @return [String]
Public Class Methods
@private
# File lib/toys/flag.rb, line 607 def initialize(str) @string = str @flags = [] @found_exact = false end
Public Instance Methods
@private
# File lib/toys/flag.rb, line 697 def add!(flag, flag_syntax, negative, exact) @flags = [] if exact && !found_exact? if exact || !found_exact? @flags << [flag, flag_syntax, negative] @found_exact = exact end self end
The number of matches that were found. @return [Integer]
# File lib/toys/flag.rb, line 631 def count @flags.size end
Whether an exact match of the string was found @return [Boolean]
# File lib/toys/flag.rb, line 623 def found_exact? @found_exact end
Whether multiple matches were found (i.e. ambiguous input). @return [Boolean]
# File lib/toys/flag.rb, line 655 def found_multiple? @flags.size > 1 end
Whether a single unique match was found. @return [Boolean]
# File lib/toys/flag.rb, line 639 def found_unique? @flags.size == 1 end
Returns an array of the matching full flag strings. @return [Array<String>]
# File lib/toys/flag.rb, line 690 def matching_flag_strings @flags.map do |_flag, flag_syntax, negative| negative ? flag_syntax.negative_flag : flag_syntax.positive_flag end end
@private
# File lib/toys/flag.rb, line 707 def merge!(other) raise "String mismatch" unless string == other.string other.instance_variable_get(:@flags).each do |flag, flag_syntax, negative| add!(flag, flag_syntax, negative, other.found_exact?) end self end
Whether no matches were found. @return [Boolean]
# File lib/toys/flag.rb, line 647 def not_found? @flags.empty? end
Return the unique {Toys::Flag}, or `nil` if not found or not unique. @return [Toys::Flag,nil]
# File lib/toys/flag.rb, line 664 def unique_flag found_unique? ? @flags.first[0] : nil end
Return whether the unique match was a hit on the negative (`–no-*`) case, or `nil` if not found or not unique. @return [Boolean,nil]
# File lib/toys/flag.rb, line 682 def unique_flag_negative? found_unique? ? @flags.first[2] : nil end
Return the unique {Toys::Flag::Syntax}, or `nil` if not found or not unique. @return [Toys::Flag::Syntax,nil]
# File lib/toys/flag.rb, line 673 def unique_flag_syntax found_unique? ? @flags.first[1] : nil end