Class: NRSER::Labs::LOTS::BoolOptConsumer

Inherits:
Consumer show all
Defined in:
lib/nrser/labs/lots/consumer.rb

Instance Method Summary collapse

Methods inherited from Consumer

#initialize

Constructor Details

This class inherits a constructor from NRSER::Labs::LOTS::Consumer

Instance Method Details

#can_consume?(tokens) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
# File 'lib/nrser/labs/lots/consumer.rb', line 105

def can_consume? tokens
  return 0 unless consumed.empty?

  first = tokens[0]

  return 1 if self.switch_tokens.include?( tokens[0] )

  return 0
end

#switch_tokensObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/nrser/labs/lots/consumer.rb', line 94

def switch_tokens
  @switches ||= names.each_with_object( Set.new ) do |name, set|
    if name.length == 1
      set << "-#{ name }"
    else
      set << "--#{ name }"
      set << "--no-#{ name }"
    end
  end
end