Module: Commonmarker::Utils

Includes:
Constants
Included in:
Config
Defined in:
lib/commonmarker/utils.rb

Constant Summary

Constants included from Constants

Constants::BOOLS

Instance Method Summary collapse

Instance Method Details

#fetch_kv(option, key, value, type) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/commonmarker/utils.rb', line 9

def fetch_kv(option, key, value, type)
  value_klass = value.class

  if Constants::BOOLS.include?(value) && BOOLS.include?(option[key])
    option[key]
  elsif option[key].is_a?(value_klass)
    option[key]
  else
    expected_type = Constants::BOOLS.include?(value) ? "Boolean" : value_klass.to_s
    raise TypeError, "#{type} option `:#{key}` must be #{expected_type}; got #{option[key].class}"
  end
end