<commit_before>module Fog
  module Parsers
    module AWS
      module ELB

        class DescribeLoadBalancers < Fog::Parsers::Base

          def reset
            @load_balancer = { 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [] }, 'HealthCheck' => {} }
            @listener = { }
            @listener_descriptions = []
            @listener_description = { 'PolicyNames' => [], 'Listener' => {} }
            @results = { 'LoadBalancerDescriptions' => [] }
            @response = { 'DescribeLoadBalancersResult' => {}, 'ResponseMetadata' => {} }
          end

          def start_element(name, attrs = [])
            case name
            when 'ListenerDescriptions'
              @in_listeners = true
            when 'Instances'
              @in_instances = true
            when 'AvailabilityZones'
              @in_availability_zones = true
            when 'PolicyNames'
              @in_policy_names = true
            when 'Policies'
              @in_policies = true
            when 'LBCookieStickinessPolicies'
              @in_lb_cookies = true
            when 'AppCookieStickinessPolicies'
              @in_app_cookies = true
            end
            @value = ''
          end

          def end_element(name)
            case name
            when 'member'
              if @in_policy_names
                @listener_description['PolicyNames'] << @value
              elsif @in_availability_zones
                @load_balancer['AvailabilityZones'] << @value
              elsif @in_listeners
                @listener_description['Listener'] = @listener
                @listener_descriptions << @listener_description
                @load_balancer['ListenerDescriptions'] = @listener_descriptions
                @listener_description = { 'PolicyNames' => [], 'Listener' => {} }
              elsif @in_app_cookies
                @load_balancer['Policies']['AppCookieStickinessPolicies'] << @value
              elsif @in_lb_cookies
                @load_balancer['Policies']['LBCookieStickinessPolicies'] << @value
              elsif !@in_instances && !@in_policies
                @results['LoadBalancerDescriptions'] << @load_balancer
                @load_balancer = { 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [] }, 'HealthCheck' => {} }
              end

            when 'LoadBalancerName', 'DNSName'
              @load_balancer[name] = @value
            when 'CreatedTime'
              @load_balancer[name] = Time.parse(@value)

            when 'ListenerDescriptions'
              @in_listeners = false
            when 'PolicyNames'
              @in_policy_names = false
            when 'Protocol'
              @listener[name] = @value
            when 'LoadBalancerPort', 'InstancePort'
              @listener[name] = @value.to_i

            when 'Instances'<commit_msg>[elb] fixing bug with Listener parsing<commit_after>module Fog
  module Parsers
    module AWS
      module ELB

        class DescribeLoadBalancers < Fog::Parsers::Base

          def reset
            @load_balancer = { 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [] }, 'HealthCheck' => {} }
            @listener_description = { 'PolicyNames' => [], 'Listener' => {} }
            @results = { 'LoadBalancerDescriptions' => [] }
            @response = { 'DescribeLoadBalancersResult' => {}, 'ResponseMetadata' => {} }
          end

          def start_element(name, attrs = [])
            case name
            when 'ListenerDescriptions'
              @in_listeners = true
            when 'Instances'
              @in_instances = true
            when 'AvailabilityZones'
              @in_availability_zones = true
            when 'PolicyNames'
              @in_policy_names = true
            when 'Policies'
              @in_policies = true
            when 'LBCookieStickinessPolicies'
              @in_lb_cookies = true
            when 'AppCookieStickinessPolicies'
              @in_app_cookies = true
            end
            @value = ''
          end

          def end_element(name)
            case name
            when 'member'
              if @in_policy_names
                @listener_description['PolicyNames'] << @value
              elsif @in_availability_zones
                @load_balancer['AvailabilityZones'] << @value
              elsif @in_listeners
                @load_balancer['ListenerDescriptions'] << @listener_description
                @listener_description = { 'PolicyNames' => [], 'Listener' => {} }
              elsif @in_app_cookies
                @load_balancer['Policies']['AppCookieStickinessPolicies'] << @value
              elsif @in_lb_cookies
                @load_balancer['Policies']['LBCookieStickinessPolicies'] << @value
              elsif !@in_instances && !@in_policies
                @results['LoadBalancerDescriptions'] << @load_balancer
                @load_balancer = { 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [] }, 'HealthCheck' => {} }
              end

            when 'LoadBalancerName', 'DNSName'
              @load_balancer[name] = @value
            when 'CreatedTime'
              @load_balancer[name] = Time.parse(@value)

            when 'ListenerDescriptions'
              @in_listeners = false
            when 'PolicyNames'
              @in_policy_names = false
            when 'Protocol'
              @listener_description['Listener'][name] = @value
            when 'LoadBalancerPort', 'InstancePort'
              @listener_description['Listener'][name] = @value.to_i

            when 'Instances'
{'fraction_non_alphanumeric': 0.11401900316719453, 'fraction_numerical': 0.0, 'mean_word_length': 1.9368575624082232, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 45, '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': '2761555', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1591, 'n_words': 284}