Class: ProconBypassMan::Procon::Macro

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/macro.rb

Defined Under Namespace

Classes: BaseNestedStep, NestedStep, OnetimeNestedStep

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, steps:, force_neutral_buttons: [], &after_callback_block) ⇒ Macro

Returns a new instance of Macro.



81
82
83
84
85
86
# File 'lib/procon_bypass_man/procon/macro.rb', line 81

def initialize(name: , steps: , force_neutral_buttons: [], &after_callback_block)
  self.name = name
  self.steps = steps
  self.after_callback_block = after_callback_block
  self.force_neutral_buttons = force_neutral_buttons # 外部から呼ばれるだけ
end

Instance Attribute Details

#after_callback_blockObject

Returns the value of attribute after_callback_block.



79
80
81
# File 'lib/procon_bypass_man/procon/macro.rb', line 79

def after_callback_block
  @after_callback_block
end

#force_neutral_buttonsObject

Returns the value of attribute force_neutral_buttons.



79
80
81
# File 'lib/procon_bypass_man/procon/macro.rb', line 79

def force_neutral_buttons
  @force_neutral_buttons
end

#nameObject

Returns the value of attribute name.



79
80
81
# File 'lib/procon_bypass_man/procon/macro.rb', line 79

def name
  @name
end

#stepsObject

Returns the value of attribute steps.



79
80
81
# File 'lib/procon_bypass_man/procon/macro.rb', line 79

def steps
  @steps
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/procon_bypass_man/procon/macro.rb', line 112

def finished?
  steps.empty?
end

#next_stepObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/procon_bypass_man/procon/macro.rb', line 88

def next_step
  step = steps.first
  if step.is_a?(Symbol)
    return steps.shift
  end

  if step.is_a?(Hash)
    nested_step =
      if step[:continue_for]
        NestedStep.new(step)
      else
        OnetimeNestedStep.new(step)
      end

    if nested_step.over?
      steps.shift # NestedStepを破棄する
      self.after_callback_block.call if self.after_callback_block && steps.empty?
      return next_step
    else
      return nested_step.next_step
    end
  end
end

#ongoing?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/procon_bypass_man/procon/macro.rb', line 116

def ongoing?
  !finished?
end