diff options
Diffstat (limited to 'logic/cartridge/affixes.rb')
-rw-r--r-- | logic/cartridge/affixes.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/logic/cartridge/affixes.rb b/logic/cartridge/affixes.rb new file mode 100644 index 0000000..0b40fa2 --- /dev/null +++ b/logic/cartridge/affixes.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require_relative '../helpers/hash' +require_relative './default' + +module NanoBot + module Logic + module Cartridge + module Affixes + def self.get(cartridge, interface, direction, kind) + affix = [ + { + exists: (Helpers::Hash.fetch(cartridge, [:interfaces, direction]) || {}).key?(kind), + value: Helpers::Hash.fetch(cartridge, [:interfaces, direction, kind]) + }, + { + exists: (Helpers::Hash.fetch(cartridge, [:interfaces, interface, direction]) || {}).key?(kind), + value: Helpers::Hash.fetch(cartridge, [:interfaces, interface, direction, kind]) + } + ].filter { |candidate| candidate[:exists] }.last + + if affix.nil? + return Helpers::Hash.fetch( + Default.instance.values, [:interfaces, interface, direction, kind] + ) + end + + affix[:value] + end + end + end + end +end |