Module: Dieses::Application::Batch
- Defined in:
- lib/dieses/application/batch.rb
Constant Summary collapse
- PAPERS =
%i[a4 a5].freeze
- ORIENTATIONS =
Orientation.values
Class Method Summary collapse
-
.all(papers: PAPERS, orientations: ORIENTATIONS) ⇒ Object
rubocop:disable Metrics/MethodLength codebeat:disable.
- .defaults ⇒ Object
-
.from_json_file(file) ⇒ Object
rubocop:enable Metrics/MethodLength.
- .index(productions) ⇒ Object
- .to_json_file(file, productions) ⇒ Object
Class Method Details
.all(papers: PAPERS, orientations: ORIENTATIONS) ⇒ Object
rubocop:disable Metrics/MethodLength codebeat:disable
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# 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) ⇒ Object
rubocop:enable Metrics/MethodLength
113 114 115 116 117 118 |
# 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) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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) ⇒ Object
120 121 122 123 124 |
# 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 |