Class: Boxcars::TrainAction

Inherits:
Object
  • Object
show all
Defined in:
lib/boxcars/train/train_action.rb

Overview

Train’s action to take.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(boxcar:, log:, boxcar_input: nil) ⇒ Boxcars::TrainAction

record for a train action

Parameters:

  • boxcar (String)

    The boxcar to run.

  • log (String)

    The log of the action.

  • boxcar_input (String) (defaults to: nil)

    The input to the boxcar.



13
14
15
16
17
# File 'lib/boxcars/train/train_action.rb', line 13

def initialize(boxcar:, log:, boxcar_input: nil)
  @boxcar_input = boxcar_input
  @boxcar = boxcar
  @log = log
end

Instance Attribute Details

#boxcarObject

Returns the value of attribute boxcar.



6
7
8
# File 'lib/boxcars/train/train_action.rb', line 6

def boxcar
  @boxcar
end

#boxcar_inputObject

Returns the value of attribute boxcar_input.



6
7
8
# File 'lib/boxcars/train/train_action.rb', line 6

def boxcar_input
  @boxcar_input
end

#logObject

Returns the value of attribute log.



6
7
8
# File 'lib/boxcars/train/train_action.rb', line 6

def log
  @log
end

Class Method Details

.from_result(result:, boxcar:, log:) ⇒ Boxcars::TrainAction

build a train action from a result

Parameters:

  • result (Boxcars::Result)

    The result to build from.

  • boxcar (String)

    The boxcar to run.

  • log (String)

    The log of the action.

Returns:



24
25
26
# File 'lib/boxcars/train/train_action.rb', line 24

def self.from_result(result:, boxcar:, log:)
  new(boxcar: boxcar, boxcar_input: result.to_answer, log: log)
end