Skip to content

Ability to add your own cells value encoders (converters) #118

@DmitriyFirsov

Description

@DmitriyFirsov

I propose to make the converter this way:

class Converter
      BUILD_IN_CONVERTERS = [
        # build-in converters from this https://github.com/pythonicrubyist/creek/blob/master/lib/creek/styles/converter.rb#L41
      ]

      def initialize(custom_converters: [])
        @_converters = custom_converters + BUILD_IN_CONVERTERS
      end

      def call(value, type, style, options = {})
        @_converters.each do |converter|
          if converter.is_support?(value, type, style, options)
            return converter.convert(value, type, style, options)
          end
        end

        raise StandardError, "Not found converter for cell #{options[:cell_name].to_s} with type #{type.to_s} and style #{style.to_s}"
      end
    end

Base value converter class

      class Base

        def is_support?(value, type, style, options)
          false
        end

        def convert(value, type, style, options)
          raise NotImplementedError
        end

      end

and pass to options cell name, sheet name, and raw sharing strings (in my case need to convert them to HTML with styles)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions