Class: Factorix::CLI::Commands::Blueprint::Encode

Inherits:
Factorix::CLI::Commands::Base show all
Defined in:
lib/factorix/cli/commands/blueprint/encode.rb

Overview

Encode JSON to a Factorio blueprint string

Instance Method Summary collapse

Methods inherited from Factorix::CLI::Commands::Base

backup_support!, confirmable!, inherited, require_game_stopped!

Instance Method Details

#call(file: nil, output: nil) ⇒ void

This method returns an undefined value.

Execute the encode command

Parameters:

  • file (String, nil) (defaults to: nil)

    Path to JSON file

  • output (String, nil) (defaults to: nil)

    Output file path



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/factorix/cli/commands/blueprint/encode.rb', line 27

def call(file: nil, output: nil, **)
  json_string = file ? Pathname(file).read : $stdin.read
  blueprint = Factorix::Blueprint.new(JSON.parse(json_string))
  blueprint_string = blueprint.encode

  if output
    Pathname(output).write(blueprint_string)
  else
    out.print blueprint_string
  end
end