<commit_before># encoding utf-8

require_relative 'segment'

module Carto
  module Tracking
    module Formats
      class Internal
        def initialize(hash)
          @hash = hash ? hash.with_indifferent_access : Hash.new
        end

        # Symbol should be provided as a snake-case'd version the record's model class name.
        # The id of said record should be provided with key: snake-case'd identifier + '_id'
        # Only Carto:: records allowed!
        #  Ex.: :super_duper_mdoel -> Carto::SuperDuperModel; { super_duper_model_id: xxx }
        def fetch_record!(symbol)
          symbol_string = symbol.to_s.downcase
          record_class_name = "Carto::#{symbol_string.camelize}".freeze
          record_id_key = "#{symbol_string}_id".freeze
          record_id = @hash[record_id_key]

          record_class_name.constantize.find(record_id)
        rescue
          record_id ? (raise Carto::LoadError.new("#{record_class_name} not found")) : nil
        end

        def to_hash
          @hash
        end

        def to_segment
          user = fetch_record!(:user)
          visualization = fetch_record!(:visualization)

          Carto::Tracking::Formats::Segment.new(user: user,
                                                visualization: visualization,
                                                hash: @hash).to_hash
        end

        def to_hubspot
          Hash.new
        end
      end
    end
  end
end
<commit_msg>connect to_hubspot internal format method<commit_after># encoding utf-8

require_relative 'segment'

module Carto
  module Tracking
    module Formats
      class Internal
        def initialize(hash)
          @hash = hash ? hash.with_indifferent_access : Hash.new
        end

        # Symbol should be provided as a snake-case'd version the record's model class name.
        # The id of said record should be provided with key: snake-case'd identifier + '_id'
        # Only Carto:: records allowed!
        #  Ex.: :super_duper_mdoel -> Carto::SuperDuperModel; { super_duper_model_id: xxx }
        def fetch_record!(symbol)
          symbol_string = symbol.to_s.downcase
          record_class_name = "Carto::#{symbol_string.camelize}".freeze
          record_id_key = "#{symbol_string}_id".freeze
          record_id = @hash[record_id_key]

          record_class_name.constantize.find(record_id)
        rescue
          record_id ? (raise Carto::LoadError.new("#{record_class_name} not found")) : nil
        end

        def to_hash
          @hash
        end

        def to_segment
          user = fetch_record!(:user)
          visualization = fetch_record!(:visualization)

          Carto::Tracking::Formats::Segment.new(user: user,
                                                visualization: visualization,
                                                hash: @hash).to_hash
        end

        def to_hubspot
          user = fetch_record!(:user)
          visualization = fetch_record!(:visualization)

          Carto::Tracking::Formats::Segment.new(user: user,
                                                visualization: visualization,
                                                hash: @hash).to_hash
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.0792965134217834, 'fraction_numerical': 0.000617093489663684, 'mean_word_length': 1.8289703315881327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5309987', 'n_tokens_mistral': 882, 'n_tokens_neox': 855, 'n_words': 211}