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.



5
6
7
# File 'lib/eac_ruby_utils/options_consumer.rb', line 5

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

Instance Method Details

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



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

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



23
24
25
# File 'lib/eac_ruby_utils/options_consumer.rb', line 23

def left_data
  data.dup
end

#validateObject



17
18
19
20
21
# File 'lib/eac_ruby_utils/options_consumer.rb', line 17

def validate
  return if data.empty?

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