<commit_before>require "nokogiri"
require "mobiledoc_html_renderer/utils/section_types"
require "mobiledoc_html_renderer/utils/tag_names"
require "mobiledoc_html_renderer/cards/image"

module Mobiledoc
  class Renderer_0_2
    MOBILEDOC_VERSION = '0.2.0'

    include Mobiledoc::Utils::SectionTypes
    include Mobiledoc::Utils::TagNames

    attr_accessor :root, :marker_types, :sections, :doc, :cards, :card_options, :unknown_card_handler

    def initialize(mobiledoc, state)
      version, section_data = *mobiledoc.values_at('version', 'sections')
      self.marker_types, self.sections = *section_data

      self.doc = Nokogiri::HTML.fragment('')
      self.root = create_document_fragment
      self.cards = state[:cards]
      self.card_options = state[:card_options]
      self.unknown_card_handler = state[:unknown_card_handler]
    end

    def render
      root = create_document_fragment

      sections.each do |section|
        rendered = render_section(section)
<commit_msg>Validate version in individual renderers<commit_after>require "nokogiri"
require "mobiledoc_html_renderer/utils/section_types"
require "mobiledoc_html_renderer/utils/tag_names"
require "mobiledoc_html_renderer/cards/image"

module Mobiledoc
  class Renderer_0_2
    MOBILEDOC_VERSION = '0.2.0'

    include Mobiledoc::Utils::SectionTypes
    include Mobiledoc::Utils::TagNames

    attr_accessor :root, :marker_types, :sections, :doc, :cards, :card_options, :unknown_card_handler

    def initialize(mobiledoc, state)
      version, section_data = *mobiledoc.values_at('version', 'sections')
      validate_version(version)

      self.marker_types, self.sections = *section_data

      self.doc = Nokogiri::HTML.fragment('')
      self.root = create_document_fragment
      self.cards = state[:cards]
      self.card_options = state[:card_options]
      self.unknown_card_handler = state[:unknown_card_handler]
    end

    def validate_version(version)
      if version != self.class::MOBILEDOC_VERSION
        raise StandardError.new(%Q[Unexpected Mobiledoc version "#{version}"]);
      end
    end

    def render
      root = create_document_fragment

      sections.each do |section|
        rendered = render_section(section)

{'fraction_non_alphanumeric': 0.0948314606741573, 'fraction_numerical': 0.0044943820224719105, 'mean_word_length': 4.26241134751773, 'pattern_counts': {'":': 0, '<': 3, '<?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': '123670', 'n_tokens_mistral': 699, 'n_tokens_neox': 684, 'n_words': 129}