Sha256: b5dd9c27fd55ccb660f9e1a8f267a59eb7f675b9be68f60dcba3c828380381b1

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 Bytes

Contents

class BMC::Serializers::XLSX < BMC::Serializers::Base
  def render_inline
    headers, *data = formatted_data

    SpreadsheetArchitect.to_xlsx(
      headers:,
      data:,
      freeze_headers: true,
      range_styles: range_styles(data[0]),
    )
  end

  def render_file(file_path)
    File.binwrite(file_path, render_inline)
  end

  private

  def range_styles(row)
    return [] if row.nil?

    date_range_styles(row) + time_range_styles(row)
  end

  def date_range_styles(row)
    row.each_index.select { row[_1].is_a?(Date) }.map do |col|
      {range: {rows: :all, columns: col}, styles: {format_code: "dd/mm/yyyy"}}
    end
  end

  def time_range_styles(row)
    row.each_index.select { row[_1].is_a?(Time) }.map do |col|
      {range: {rows: :all, columns: col}, styles: {format_code: "dd/mm/yyyy hh:mm:ss"}}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bmc-1.6.1 app/serializers/bmc/serializers/xlsx.rb
bmc-1.6.0 app/serializers/bmc/serializers/xlsx.rb