<commit_before># encoding: utf-8

module CartoDB
  module NamedMapsWrapper

		class Presenter

			def initialize(visualization, options, configuration)
        @visualization  = visualization
        @options        = options
        @configuration	= configuration

        #TODO: Check options has proper values

        @fetched				= false
      end #initialize

      def to_poro
      	named_map = fetch if !@fetched

        template_data = named_map.template.fetch(:template)

        layers = @visualization.layers(:cartodb)
        layers_data = Array.new

        layers.each { |layer|
          layer_vizjson = Layer::Presenter.new(layer, @options, @configuration).to_vizjson_v2
          layers_data.push({
            layer_name: layer_vizjson[:options][:layer_name],
            legend: layer_vizjson[:legend],
            infowindow: layer_vizjson[:infowindow]
          })
        }

        params = {}
        template_data[:placeholders].each { |key, value|
          params[key] = value[:default]
        }

        poro = {<commit_msg>CDB-1648 Removed infowindow and legend fields from named maps if they contain no active fields/data<commit_after># encoding: utf-8

module CartoDB
  module NamedMapsWrapper

		class Presenter

			def initialize(visualization, options, configuration)
        @visualization  = visualization
        @options        = options
        @configuration	= configuration

        #TODO: Check options has proper values

        @fetched				= false
      end #initialize

      def to_poro
      	named_map = fetch if !@fetched

        template_data = named_map.template.fetch(:template)

        layers = @visualization.layers(:cartodb)
        layers_data = Array.new

        layers.each { |layer|
          #TODO Remove this dependency by having a .getVizjsonLayers at visualization object
          layer_vizjson = Layer::Presenter.new(layer, @options, @configuration).to_vizjson_v2
          data = {
            layer_name: layer_vizjson[:options][:layer_name]
          }
          
          if layer_vizjson[:infowindow].fetch('fields').size > 0
            data[:infowindow] = layer_vizjson[:infowindow]
          end
          if layer_vizjson[:legend].fetch('type') != "none"
            data[:legend] = layer_vizjson[:legend]
          end

          layers_data.push(data)
        }

        params = {}
        template_data[:placeholders].each { |key, value|
          params[key] = value[:default]
        }

        poro = {
{'fraction_non_alphanumeric': 0.0895582329317269, 'fraction_numerical': 0.0036144578313253013, 'mean_word_length': 2.2392717815344603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4044914', 'n_tokens_mistral': 745, 'n_tokens_neox': 688, 'n_words': 156}