Sha256: 1102d59858fec2d41469204d0232b87ffb3bba1fa553968b1041e8a4db9e2562

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

# -*- coding: utf-8 -*-
# frozen_string_literal: true

require 'write_xlsx/package/xml_writer_simple'
require 'write_xlsx/utility'

module Writexlsx
  module Package
    class RichValue
      include Writexlsx::Utility

      attr_accessor :embedded_images

      def initialize
        @writer          = Package::XMLWriterSimple.new
        @embedded_images = []
      end

      def set_xml_writer(filename)
        @writer.set_xml_writer(filename)
      end

      def assemble_xml_file
        write_xml_declaration do
          write_rv_data
        end
      end

      private

      def write_rv_data
        xmlns = 'http://schemas.microsoft.com/office/spreadsheetml/2017/richdata'

        attributes = [
          ['xmlns', xmlns],
          ['count', @embedded_images.size]
        ]

        @writer.tag_elements('rvData', attributes) do
          @embedded_images.each_with_index do |image, index|
            write_rv(index, image[2], image[3])
          end
        end
      end

      #
      # Write the <rv> element.
      #
      def write_rv(index, description, decorative)
        value = 5
        value = 6 if ptrue?(decorative)

        attributes = [['s',  0]]

        @writer.tag_elements('rv', attributes) do
          write_v(index)
          write_v(value)
          write_v(description) if ptrue?(description)
        end
      end

      #
      # Write the <v> element.
      #
      def write_v(data)
        @writer.data_element('v', data)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
write_xlsx-1.12.1 lib/write_xlsx/package/rich_value.rb
write_xlsx-1.12.0 lib/write_xlsx/package/rich_value.rb