Class: 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 Consumer

Instance Method Details

#can_consume?(tokens) ⇒ Boolean

Returns:

  • (Boolean)


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

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



82
83
84
85
86
87
88
89
90
91
# File 'lib/nrser/labs/lots/consumer.rb', line 82

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