class Toys::Flag::Resolution

The result of looking up a flag by name.

Attributes

string[R]

The flag string that was looked up @return [String]

Public Class Methods

new(str) click to toggle source

@private

# File lib/toys/flag.rb, line 607
def initialize(str)
  @string = str
  @flags = []
  @found_exact = false
end

Public Instance Methods

add!(flag, flag_syntax, negative, exact) click to toggle source

@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
count() click to toggle source

The number of matches that were found. @return [Integer]

# File lib/toys/flag.rb, line 631
def count
  @flags.size
end
found_exact?() click to toggle source

Whether an exact match of the string was found @return [Boolean]

# File lib/toys/flag.rb, line 623
def found_exact?
  @found_exact
end
found_multiple?() click to toggle source

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
found_unique?() click to toggle source

Whether a single unique match was found. @return [Boolean]

# File lib/toys/flag.rb, line 639
def found_unique?
  @flags.size == 1
end
matching_flag_strings() click to toggle source

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
merge!(other) click to toggle source

@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
not_found?() click to toggle source

Whether no matches were found. @return [Boolean]

# File lib/toys/flag.rb, line 647
def not_found?
  @flags.empty?
end
unique_flag() click to toggle source

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
unique_flag_negative?() click to toggle source

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
unique_flag_syntax() click to toggle source

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