Sha256: 91a69d77e72a2b017c26284cb8625f238105a2e44c15a96b81e03f09a38ac40d

Contents?: true

Size: 884 Bytes

Versions: 5

Compression:

Stored size: 884 Bytes

Contents

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

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

  def render_file(file_path)
    File.open(file_path, "w+b") do |f|
      f.write(render_inline)
    end
  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
      {range: {rows: :all, columns: _1}, styles: {format_code: "dd/mm/yyyy"}}
    end
  end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
agilibox-1.11.0 app/serializers/agilibox/serializers/xlsx.rb
agilibox-1.10.5 app/serializers/agilibox/serializers/xlsx.rb
agilibox-1.10.2 app/serializers/agilibox/serializers/xlsx.rb
agilibox-1.10.1 app/serializers/agilibox/serializers/xlsx.rb
agilibox-1.10.0 app/serializers/agilibox/serializers/xlsx.rb