<commit_before>module ArticleJSON
  module Export
    module AMP
      module Elements
        class Base
          # @param [ArticleJSON::Elements::Base] element
          def initialize(element)
            @element = element
          end

          # Export a HTML node out of the given element
          # Dynamically looks up the right export-element-class, instantiates it
          # and then calls the #build method.
          # @return [Nokogiri::HTML::Node]
          def export
            exporter = self.class == Base ? self.class.build(@element) : self
            exporter.export unless exporter.nil?
          end

          private

          def create_element(tag, *args)
            Nokogiri::HTML.fragment('').document.create_element(tag.to_s, *args)
          end

          def create_text_node(text)
            Nokogiri::HTML.fragment(text).children.first
          end

          class << self
            # Instantiate the correct sub class for a given element
            # @param [ArticleJSON::Elements::Base] element
            # @return [ArticleJSON::Export::HTML::Elements::Base]
            def build(element)
              klass = exporter_by_type(element.type)
              klass.new(element) unless klass.nil?
            end

            # Look up the correct exporter class based on the element type
            # @param [Symbol] type
            # @return [ArticleJSON::Export::HTML::Elements::Base]
            def exporter_by_type(type)
              {
                text: Text,
                paragraph: Paragraph,
                heading: Heading,
                list: List,
                quote: Quote,
              }[type.to_sym]
            end
          end
        end
      end
    end
  end
end<commit_msg>Add Image element in the base class<commit_after>module ArticleJSON
  module Export
    module AMP
      module Elements
        class Base
          # @param [ArticleJSON::Elements::Base] element
          def initialize(element)
            @element = element
          end

          # Export a HTML node out of the given element
          # Dynamically looks up the right export-element-class, instantiates it
          # and then calls the #build method.
          # @return [Nokogiri::HTML::Node]
          def export
            exporter = self.class == Base ? self.class.build(@element) : self
            exporter.export unless exporter.nil?
          end

          private

          def create_element(tag, *args)
            Nokogiri::HTML.fragment('').document.create_element(tag.to_s, *args)
          end

          def create_text_node(text)
            Nokogiri::HTML.fragment(text).children.first
          end

          class << self
            # Instantiate the correct sub class for a given element
            # @param [ArticleJSON::Elements::Base] element
            # @return [ArticleJSON::Export::HTML::Elements::Base]
            def build(element)
              klass = exporter_by_type(element.type)
              klass.new(element) unless klass.nil?
            end

            # Look up the correct exporter class based on the element type
            # @param [Symbol] type
            # @return [ArticleJSON::Export::HTML::Elements::Base]
            def exporter_by_type(type)
              {
                text: Text,
                paragraph: Paragraph,
                heading: Heading,
                list: List,
                quote: Quote,
                image: Image,
              }[type.to_sym]
            end
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07872696817420435, 'fraction_numerical': 0.0, 'mean_word_length': 1.5721464465183057, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3215812', 'n_tokens_mistral': 926, 'n_tokens_neox': 884, 'n_words': 257}