<commit_before>module DisplayHelper

require 'uri'

  def field_to_array(value)
      value_arr = []
      case value
          when Array then value_arr = value
          when String then value_arr.push(value)
          else
              value_arr = value.to_a
      end
   end

   def display_field(document, field_name, label, opts = {})

      if opts.key?(:dc_element)
         dc_property_string = opts[:dc_element].length > 0 ? 'property="http://purl.org/dc/terms/' + opts[:dc_element] + '"' : opts[:dc_element] 
      end


      if document.has? field_name
         values = field_to_array(document[field_name])
      else
         return nil
      end

      if opts[:search_link]
         search_field = opts.key?(:search_fields) ? opts[:search_fields] : 'all_fields'
         exact_match = opts.key?(:exact_match) ? opts[:exact_match] : false
         value_string = values.collect{ |value| search_catalog_link(strip(value), search_field, exact_match)}.join('; ')
      elsif opts[:contains_url]
         value_string = values.collect{ |url| external_link(url)}.join('; ')
      else
         value_string = values.collect{ |value| strip(value)}.join('; ')
      end

      if values.any?
         display_string  = <<-EOS
             <dt>#{label}:</dt>
             <dd #{dc_property_string}>#{value_string}</dd>
         EOS
         return display_string.html_safe
      end
   end


   def search_catalog_link(text, search_field, exact_match=false)
      if exact_match
         search_query = "\"#{text}\"".html_safe
      else
         search_query = text
      end
      return link_to text, catalog_index_path(:q => search_query, :search_field => search_field )
   end

   def external_link(url)
      if url =~ URI::regexp
         return link_to url, url
      end
   end


end<commit_msg>Adding some documentation; helps with #67<commit_after>module DisplayHelper

require 'uri'

    # Make sure that this is an array
    def field_to_array(value)
        value_arr = []
        case value
            when Array then value_arr = value
            when String then value_arr.push(value)
        else
            value_arr = value.to_a
        end
    end

    # Create the HTML to display a field
    # from a solr document
    def display_field(document, field_name, label, opts = {})
        
        # Make sure that the document actually has the
        # field we want
        if document.has? field_name
            values = field_to_array(document[field_name])
        else
            return nil
        end

        # Add a DC RDFa attribute
        if opts.key?(:dc_element)
           dc_property_string = opts[:dc_element].length > 0 ? 'property="http://purl.org/dc/terms/' + opts[:dc_element] + '"' : opts[:dc_element] 
        end

        # Display this field as a link to a search
        if opts[:search_link]
            # If no search field is specified, default to
            # searching all fields
            search_field = opts.key?(:search_fields) ? opts[:search_fields] : 'all_fields'
            exact_match = opts.key?(:exact_match) ? opts[:exact_match] : false
            value_string = values.collect{ |value| search_catalog_link(strip(value), search_field, exact_match)}.join('; ')
        elsif opts[:contains_url]
            value_string = values.collect{ |url| external_link(url)}.join('; ')
        else
            value_string = values.collect{ |value| strip(value)}.join('; ')
        end

        if values.any?
            display_string  = <<-EOS
             <dt>#{label}:</dt>
             <dd #{dc_property_string}>#{value_string}</dd>
            EOS
            return display_string.html_safe
        end
    end

    def search_catalog_link(text, search_field, exact_match=false)
        if exact_match
            search_query = "\"#{text}\"".html_safe
        else
            search_query = text
        end
        return link_to text, catalog_index_path(:q => search_query, :search_field => search_field )
    end

    def external_link(url)
        if url =~ URI::regexp
            return link_to url, url
        end
    end
end
{'fraction_non_alphanumeric': 0.10167842374118219, 'fraction_numerical': 0.0009729992702505473, 'mean_word_length': 2.1802010827532867, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '3194747', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1203, 'n_words': 294}