class TimetableExporter

Public Class Methods

new(table, stratagy) click to toggle source

Contract IsA, IsA => Any

# File lib/tmis/engine/export/timetable_exporter.rb, line 46
def initialize(table, stratagy)
  @table = table
  @stratagy = stratagy
end

Public Instance Methods

export() click to toggle source

Contract None => IsA

# File lib/tmis/engine/export/timetable_exporter.rb, line 52
def export
  rows_export
  @table
end

Private Instance Methods

columns() click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 96
def columns
  @stratagy.columns.zip((3..(@stratagy.columns.to_a.size * 2) + (3 - 1)).each_slice(2))
end
columns_export(row_ent, rows) click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 70
def columns_export(row_ent, rows)
  columns.each do |ent, cols|
    columns_format(rows, cols)
    @table[rows[0], cols[0]] = @stratagy.column_value(ent)
    export_studies(@stratagy.studies(row_ent, ent), rows, cols)
  end
end
columns_format(rows, cols) click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 129
def columns_format(rows, cols)
  @table.column(cols[0]).width = 25
  @table.merge(rows[0], cols[0], rows[0], cols[1])
end
export_studies(studies, rows, cols) click to toggle source

Contract ArrayOf, [Pos, Pos], [Pos, Pos] => Any

# File lib/tmis/engine/export/timetable_exporter.rb, line 79
def export_studies(studies, rows, cols)
  prepare_studies(studies).each do |number, studies|
    if studies.size == 1
      @table.merge(real_row(rows, number), cols[0], real_row(rows, number) + 1, cols[0])
      @table.merge(real_row(rows, number), cols[1], real_row(rows, number) + 1, cols[1])
    end
    studies.each_with_index do |study, i|
      @table[real_row(rows, number) + i, cols[0]] = study.to_s
      @table[real_row(rows, number) + i, cols[1]] = study.cabinet.title
    end
  end
end
pair_format(rows, row) click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 123
def pair_format(rows, row)
  @table.row((rows[0] - 1) + row * 2).height = 30
  @table.row(rows[0] + row * 2).height = 30
  @table.merge((rows[0] - 1) + row * 2, 2, rows[0] + row * 2, 2)
end
prepare_studies(studies) click to toggle source

Contract ArrayOf => ({ Pos => ArrayOf })

# File lib/tmis/engine/export/timetable_exporter.rb, line 101
def prepare_studies(studies)
  studies.sort_by(&:number).group_by(&:number)
end
real_row(rows, number) click to toggle source

Contract ArrayOf, Pos => Pos

# File lib/tmis/engine/export/timetable_exporter.rb, line 106
def real_row(rows, number)
  (rows[0] - 1) + (number * 2)
end
rows() click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 92
def rows
  @stratagy.rows.zip((1..(13 * @stratagy.rows.to_a.size)).each_slice(13).map{ |i| [i.first, i.last] })
end
rows_export() click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 58
def rows_export
  rows.each do |entity, rows|
    rows_format(rows)
    @table[rows[0] + 1, 1] = @stratagy.row_value(entity)
    (1..6).each do |row|
      pair_format(rows, row)
      @table[(rows[0] - 1) + row * 2, 2] = "#{row} пара"
    end
    columns_export(entity, rows)
  end
end
rows_format(rows) click to toggle source
# File lib/tmis/engine/export/timetable_exporter.rb, line 110
def rows_format(rows)
  @table.merge(rows[0] + 1, 1, rows[1], 1)
  format = Spreadsheet::Format.new
  format.rotation = 90
  format.horizontal_align = :center
  format.vertical_align = :middle
  format.top = :medium
  format.bottom = :medium
  format.right = :medium
  format.left = :medium
  @table.format(rows[0] + 1, 1, format)
end