<commit_before>require 'representable/xml'
module ProductTestRepresenter
  include API::Representer

  property :name
  property :cms_id
  property :measure_id, getter: ->(_args) { measure_ids.first }
  property :type, getter: ->(_args) { _type == 'MeasureTest' ? 'measure' : 'filter' }
  property :state

  module ProviderRepresenter
    include Representable::XML
    include Representable::JSON

    module AddressRepresenter
      include Representable::XML
      include Representable::JSON

      self.representation_wrap = ->(obj) { obj.key?(:doc) ? :address : false }

      property :street, getter: ->(_) { self['street'].first }
      property :city
      property :state
      property :zip, getter: -> (_) { self['zip'] }
      property :country
    end

    self.representation_wrap = ->(obj) { obj.key?(:doc) ? :provider : false }

    property :npi, getter: ->(_) { self['npis'].first }
    property :tin, getter: ->(_) { self['tins'].first }
    property :address, extend: AddressRepresenter, if: ->(_) { self['addresses'] }, getter: ->(_) { self['addresses'].first }
  end

  hash :provider_filters, :if => ->(_) { _type == 'FilteringTest' && options.filters.key?('providers') }, :wrap => :filters,
                          :as => :filters, :extend => ProviderRepresenter,
                          :getter => (lambda do |*|
                            filters_copy = options.filters.clone
                            filters_copy['provider'] = filters_copy.delete 'providers'
                            filters_copy
                          end)

  hash :other_filters, :getter => ->(_) { options.filters.map { |filter_type, filter_val| [filter_type.to_s.singularize, filter_val.first] }.to_h },
                       :if => ->(_) { _type == 'FilteringTest' && !options.filters['providers'] }, :wrap => :filters, :as => :filters<commit_msg>Exclude filters from response if filtering test is not ready<commit_after>require 'representable/xml'
module ProductTestRepresenter
  include API::Representer

  property :name
  property :cms_id
  property :measure_id, getter: ->(_args) { measure_ids.first }
  property :type, getter: ->(_args) { _type == 'MeasureTest' ? 'measure' : 'filter' }
  property :state

  module ProviderRepresenter
    include Representable::XML
    include Representable::JSON

    module AddressRepresenter
      include Representable::XML
      include Representable::JSON

      self.representation_wrap = ->(obj) { obj.key?(:doc) ? :address : false }

      property :street, getter: ->(_) { self['street'].first }
      property :city
      property :state
      property :zip, getter: -> (_) { self['zip'] }
      property :country
    end

    self.representation_wrap = ->(obj) { obj.key?(:doc) ? :provider : false }

    property :npi, getter: ->(_) { self['npis'].first }
    property :tin, getter: ->(_) { self['tins'].first }
    property :address, extend: AddressRepresenter, if: ->(_) { self['addresses'] }, getter: ->(_) { self['addresses'].first }
  end

  hash :provider_filters, :if => ->(_) { _type == 'FilteringTest' && options.filters.key?('providers') && state == :ready }, :wrap => :filters,
                          :as => :filters, :extend => ProviderRepresenter,
                          :getter => (lambda do |*|
                            filters_copy = options.filters.clone
                            filters_copy['provider'] = filters_copy.delete 'providers'
                            filters_copy
                          end)

  hash :other_filters, :getter => ->(_) { options.filters.map { |filter_type, filter_val| [filter_type.to_s.singularize, filter_val.first] }.to_h },
                       :if => ->(_) { _type == 'FilteringTest' && !options.filters['providers'] && state == :ready },
                       :wrap => :filters, :as => :filters
{'fraction_non_alphanumeric': 0.14919144496609285, 'fraction_numerical': 0.0, 'mean_word_length': 2.628192999053926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7140191', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1084, 'n_words': 248}