<commit_before>require "gds_api/publishing_api"
require_relative "../app/presenters/finder_content_item_presenter"
require_relative "../app/presenters/finder_signup_content_item_presenter"

class PublishingApiFinderPublisher
  def initialize(metadata, schemae, log = true)
    @metadata = metadata
    @schemae = schemae
    @log = log
  end

  def call
    metadata.zip(schemae).map do |metadata, schema|
      if metadata[:file].has_key?("content_id") && !preview_only?(metadata)
        publish metadata, schema
      elsif preview_only?(metadata)
        if preview_domain_or_not_production?
          publish metadata, schema
        else
          puts "didn't publish #{metadata[:file]["name"]} because it is preview_only" if @log
        end
      else
        puts "didn't publish #{metadata[:file]["name"]} because it doesn't have a content_id" if @log
      end
    end
  end

private
  attr_reader :schemae, :metadata

  def publish metadata, schema
    export_finder(metadata, schema)
    export_signup(metadata) if metadata[:file].has_key?("signup_content_id")
  end

  def preview_only? metadata
    metadata[:file]["preview_only"] == true
  end

  def preview_domain_or_not_production?<commit_msg>Add some brackets ala the styleguide<commit_after>require "gds_api/publishing_api"
require_relative "../app/presenters/finder_content_item_presenter"
require_relative "../app/presenters/finder_signup_content_item_presenter"

class PublishingApiFinderPublisher
  def initialize(metadata, schemae, log = true)
    @metadata = metadata
    @schemae = schemae
    @log = log
  end

  def call
    metadata.zip(schemae).map do |metadata, schema|
      if metadata[:file].has_key?("content_id") && !preview_only?(metadata)
        publish metadata, schema
      elsif preview_only?(metadata)
        if preview_domain_or_not_production?
          publish metadata, schema
        else
          puts "didn't publish #{metadata[:file]["name"]} because it is preview_only" if @log
        end
      else
        puts "didn't publish #{metadata[:file]["name"]} because it doesn't have a content_id" if @log
      end
    end
  end

private
  attr_reader :schemae, :metadata

  def publish(metadata, schema)
    export_finder(metadata, schema)
    export_signup(metadata) if metadata[:file].has_key?("signup_content_id")
  end

  def preview_only?(metadata)
    metadata[:file]["preview_only"] == true
  end

  def preview_domain_or_not_production?
{'fraction_non_alphanumeric': 0.0971032231742146, 'fraction_numerical': 0.0, 'mean_word_length': 3.8458498023715415, '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': '657129', 'n_tokens_mistral': 744, 'n_tokens_neox': 731, 'n_words': 180}