Class: EacRubyUtils::OptionsConsumer

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/options_consumer.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ OptionsConsumer

Returns a new instance of OptionsConsumer.



7
8
9
# File 'lib/eac_ruby_utils/options_consumer.rb', line 7

def initialize(data)
  @data = data.with_indifferent_access
end

Instance Method Details

#consume(key, default_value = nil, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/eac_ruby_utils/options_consumer.rb', line 11

def consume(key, default_value = nil, &block)
  return default_value unless data.key?(key)

  value = data.delete(key)
  value = yield(value) if block
  value
end

#left_dataObject



25
26
27
# File 'lib/eac_ruby_utils/options_consumer.rb', line 25

def left_data
  data.dup
end

#validateObject



19
20
21
22
23
# File 'lib/eac_ruby_utils/options_consumer.rb', line 19

def validate
  return if data.empty?

  raise "Invalid keys: #{data.keys}"
end