Class: Card::Set::Abstract::Machine::EngineInput

Inherits:
Object
  • Object
show all
Defined in:
card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb,
card/tmpsets/set/mod015-card-mod-machines/abstract/machine.rb

Overview

TODO: replace with call of extended_item_cards traverse through all levels of pointers and collect all item cards as input

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine_card) ⇒ EngineInput

Returns a new instance of EngineInput.



82
83
84
85
86
87
88
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 82

def initialize machine_card
  @machine_card = machine_card
  @items = [machine_card]
  @new_input = []
  @extended = {}
  @loop_limit = 5
end

Instance Attribute Details

#new_inputObject

Returns the value of attribute new_input.



80
81
82
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 80

def new_input
  @new_input
end

Instance Method Details

#each_valid_itemObject



112
113
114
115
116
117
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 112

def each_valid_item
  until @items.empty?
    @item = @items.shift
    yield unless invalid_item?
  end
end

#invalid_item?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 119

def invalid_item?
  @item.trash || @extended[@item.id].to_i > @loop_limit
end

#pointer_itemObject



101
102
103
104
105
106
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 101

def pointer_item
  @items.insert 0, @item.item_cards.reject(&:unknown?)
  @items.flatten!
  record_item
  @item if @item != @machine_card && @item.known?
end

#processObject



90
91
92
93
94
95
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 90

def process
  each_valid_item do
    input_item = simple_item? ? @item : pointer_item
    new_input << input_item if input_item
  end
end

#record_itemObject



108
109
110
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 108

def record_item
  @extended[@item] = @extended[@item].to_i + 1
end

#simple_item?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine.rb', line 97

def simple_item?
  @item.item_cards == [@item] # no pointer card
end