<commit_before>module Terraforming
  module Resource
    class RouteTable
      include Terraforming::Util

      def self.tf(client: Aws::EC2::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::EC2::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/route_table")
      end

      def tfstate
        route_tables.inject({}) do |resources, route_table|
          attributes = {
            "id" => route_table.route_table_id,
            "vpc_id" => route_table.vpc_id,
          }

          attributes.merge!(tags_attributes_of(route_table))
          attributes.merge!(routes_attributes_of(route_table))
          attributes.merge!(propagating_vgws_attributes_of(route_table))

          resources["aws_route_table.#{module_name_of(route_table)}"] = {
            "type" => "aws_route_table",
            "primary" => {
              "id" => route_table.route_table_id,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def routes_of(route_table)
        route_table.routes.reject do |route|
          route.gateway_id.to_s == 'local' ||
          route.origin.to_s == 'EnableVgwRoutePropagation' ||
          route.destination_prefix_list_id
        end
      end

      def module_name_of(route_table)
        normalize_module_name(name_from_tag(route_table, route_table.route_table_id))
      end

      def route_tables
        @client.describe_route_tables.route_tables
      end

      def routes_attributes_of(route_table)
        routes = routes_of(route_table)
        attributes = { "route.#" => routes.length.to_s }

        routes.each do |route|
          attributes.merge!(route_attributes_of(route))
        end

        attributes
      end

      def route_attributes_of(route)
        hashcode = route_hashcode_of(route)
        attributes = {
          "route.#{hashcode}.cidr_block" => route.destination_cidr_block.to_s,
          "route.#{hashcode}.gateway_id" => route.gateway_id.to_s,
          "route.#{hashcode}.instance_id" => route.instance_id.to_s,
          "route.#{hashcode}.network_interface_id" => route.network_interface_id.to_s,
          "route.#{hashcode}.vpc_peering_connection_id" => route.vpc_peering_connection_id.to_s
        }

        attributes
      end

      def route_hashcode_of(route)
        string = "#{route.destination_cidr_block}-" <<
                 "#{route.gateway_id}-"

        instance_set = false
        if route.instance_id != ''
          string << route.instance_id.to_s
          instance_set = true
        end
<commit_msg>Add condition<commit_after>module Terraforming
  module Resource
    class RouteTable
      include Terraforming::Util

      def self.tf(client: Aws::EC2::Client.new)
        self.new(client).tf
      end

      def self.tfstate(client: Aws::EC2::Client.new)
        self.new(client).tfstate
      end

      def initialize(client)
        @client = client
      end

      def tf
        apply_template(@client, "tf/route_table")
      end

      def tfstate
        route_tables.inject({}) do |resources, route_table|
          attributes = {
            "id" => route_table.route_table_id,
            "vpc_id" => route_table.vpc_id,
          }

          attributes.merge!(tags_attributes_of(route_table))
          attributes.merge!(routes_attributes_of(route_table))
          attributes.merge!(propagating_vgws_attributes_of(route_table))

          resources["aws_route_table.#{module_name_of(route_table)}"] = {
            "type" => "aws_route_table",
            "primary" => {
              "id" => route_table.route_table_id,
              "attributes" => attributes
            }
          }

          resources
        end
      end

      private

      def routes_of(route_table)
        route_table.routes.reject do |route|
          route.gateway_id.to_s == 'local' ||
          route.origin.to_s == 'EnableVgwRoutePropagation' ||
          route.destination_prefix_list_id
        end
      end

      def module_name_of(route_table)
        normalize_module_name(name_from_tag(route_table, route_table.route_table_id))
      end

      def route_tables
        @client.describe_route_tables.route_tables
      end

      def routes_attributes_of(route_table)
        routes = routes_of(route_table)
        attributes = { "route.#" => routes.length.to_s }

        routes.each do |route|
          attributes.merge!(route_attributes_of(route))
        end

        attributes
      end

      def route_attributes_of(route)
        hashcode = route_hashcode_of(route)
        attributes = {
          "route.#{hashcode}.cidr_block" => route.destination_cidr_block.to_s,
          "route.#{hashcode}.gateway_id" => route.gateway_id.to_s,
          "route.#{hashcode}.instance_id" => route.instance_id.to_s,
          "route.#{hashcode}.network_interface_id" => route.network_interface_id.to_s,
          "route.#{hashcode}.vpc_peering_connection_id" => route.vpc_peering_connection_id.to_s
        }

        attributes
      end

      def route_hashcode_of(route)
        string = "#{route.destination_cidr_block}-" <<
                 "#{route.gateway_id}-"

        instance_set = false
        if !route.instance_id.nil? && route.instance_id != ''
          string << route.instance_id.to_s
          instance_set = true
        end

{'fraction_non_alphanumeric': 0.10118289353958143, 'fraction_numerical': 0.0007279344858962694, 'mean_word_length': 2.1805555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '2353049', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1673, 'n_words': 242}