<commit_before>module Onebox
  module Engine
    def self.included(object)
      object.extend(ClassMethods)
    end

    def self.engines
      constants.select do |constant|
        constant.to_s =~ /Onebox$/
      end.map(&method(:const_get))
    end

    attr_reader :cache

    def initialize(link, cache = Onebox.defaults)
      @url = link
      @cache = cache
    end

    def to_html
      View.new(template_name, record, true).to_html
    end

    private

    def record
      if cache.key?(@url)
        cache.fetch(@url)
      else
        cache.store(@url, data)
      end
    end

    # raises error if not defined in onebox engine
    # in each onebox, uses either Nokogiri or OpenGraph to get raw HTML from url
    def raw
      raise NoMethodError, "Engines need to implement this method"
    end
<commit_msg>we don't want to create template until it is needed in engine module #61<commit_after>module Onebox
  module Engine
    def self.included(object)
      object.extend(ClassMethods)
    end

    def self.engines
      constants.select do |constant|
        constant.to_s =~ /Onebox$/
      end.map(&method(:const_get))
    end

    attr_reader :cache
    attr_reader :view

    def initialize(link, cache = Onebox.defaults)
      @url = link
      @cache = cache
      @view = View.new(template_name, true)
    end

    def to_html
      view.to_html(record)
    end

    private

    def record
      if cache.key?(@url)
        cache.fetch(@url)
      else
        cache.store(@url, data)
      end
    end

    # raises error if not defined in onebox engine
    # in each onebox, uses either Nokogiri or OpenGraph to get raw HTML from url
    def raw
      raise NoMethodError, "Engines need to implement this method"
    end

{'fraction_non_alphanumeric': 0.07411630558722919, 'fraction_numerical': 0.0011402508551881414, 'mean_word_length': 2.2620817843866172, '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': '3352774', 'n_tokens_mistral': 541, 'n_tokens_neox': 522, 'n_words': 172}