module Dieses::Application::Batch

Constants

ORIENTATIONS
PAPERS
Production

Public Instance Methods

all(papers: PAPERS, orientations: ORIENTATIONS) click to toggle source

rubocop:disable Metrics/MethodLength codebeat:disable

# File lib/dieses/application/batch.rb, line 63
def all(papers: PAPERS, orientations: ORIENTATIONS)
  Set.new.tap do |productions|
    papers.each do |paper|
      Sheets.available.each do |sheet, proto|
        proto.variants.each do |variant|
          orientations.each do |orientation|
            productions << Production.(sheet:       sheet.to_s,
                                       variant:     variant.to_s,
                                       desc:        variant.desc,
                                       paper:       paper.to_s,
                                       orientation: orientation.to_s)
          end
        end
      end
    end
  end
end
defaults() click to toggle source

codebeat:enable

# File lib/dieses/application/batch.rb, line 82
def defaults
  Set.new(
    Sheets.defaults.map do |sheet, variant|
      Production.(sheet:       sheet.to_s,
                  variant:     variant.to_s,
                  desc:        variant.desc,
                  paper:       Paper.default.to_s,
                  orientation: Orientation.default.to_s)
    end
  )
end
from_json_file(file) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/dieses/application/batch.rb, line 113
def from_json_file(file)
  JSON.load_file(file).map do |hash|
    hash.transform_keys!(&:to_sym)
    Production.(**hash.slice(*Production.members))
  end
end
index(productions) click to toggle source
# File lib/dieses/application/batch.rb, line 94
def index(productions)
  previous = Support.hashify_by productions, :key
  current  = Support.hashify_by Batch.all, :key

  unprocessed = []
  current.each do |name, production|
    unless previous.key?(name)
      unprocessed << production

      next
    end

    production.produce = previous[name].produce
  end

  [current.values, unprocessed]
end
to_json_file(file, productions) click to toggle source
# File lib/dieses/application/batch.rb, line 120
def to_json_file(file, productions)
  content = JSON.pretty_generate(productions.map(&:to_h)).chomp

  File.write(file, "#{content}\n")
end