Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DmitriyFirsov opened this issue Jul 3, 2023 · 1 comment
Open

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

DmitriyFirsov opened this issue Jul 3, 2023 · 1 comment

Comments

@DmitriyFirsov
Copy link
Contributor

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)

@DmitriyFirsov DmitriyFirsov changed the title Ability to add your own cells value encoders Ability to add your own cells value encoders (converters) Jul 3, 2023
@DmitriyFirsov
Copy link
Contributor Author

@pythonicrubyist What do you think of my proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant